我使用 libary easing 滚动到 ankor,但是如果我点击第二个 ankor,我的代码不起作用,它会再次跳到顶部,然后根本不起作用。这是我正在处理的主页:
这是我使用的 jq:
$(function() {
//catch all the clicks on tags
$("a").click(function() {
//check if it has a #
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
$("body,html").animate({
scrollTop : toPosition
},2000,"easeOutExpo");
return false;
}
});
if(location.hash) {
var hash = location.hash;
window.scroll(0,0);
$("a[href="+hash+"]").click();
}
});
如果有人能真诚地帮助我就好了 奥利弗