Hello everyone!
i am trying to use jquery scrollto but i m certainly stuck!
the codes i m trying to use below: where am i wrong? or any advise? thnx.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.easing.1.3.js" type="text/javascript"></script>
<script>
$(function() {
// catch all clicks on a tags
$("a").click(function() {
// check if has hash
if(this.hash) {
// get rid of the # sign
var hash = this.hash.substr(1);
// get the position of the <a name="">
var $toElement = $("a[name="+hash+"]");
var toPosition = $toElement.position().top;
// scroll/animate to that element
$("body,html").animate({
scrollTop : toPosition
},1000,"easeOutExpo");
// don't do the jump
return false;
}
});
if(location.hash) {
window.scroll(0,0);
$("a[href="+location.hash+"]").click();
}
$(window).bind("hashchange",function(e) {
//alert( $("body")[0].scrollTop );
window.scroll(0,$("body")[0].scrollTop);
$("a[href="+location.hash+"]").click();
});
});
</script>
- <li><a href="#a1">1</a></li>
- <li><a href="#a2">2</a></li>
- <li><a href="#a3">3</a></li>
- <li><a href="#a4">4</a></li>