我在页面上有多个scrollTo。问题在于,在第一次点击时它有点偏离正确的标准,但在后续点击之后正确。我能做些什么来纠正这一点。我的代码看起来像下面?:jQuery scrollTo只有在第二次点击后才能正常工作
var newHash;
$(".nav-right li a").on('click', function(event) {
newHash = $(this).attr("id");
if (this.hash !== "") {
// Store hash
hash = $("h2" + "#" + $(this).attr("id"));
$('html, body').stop().animate({
scrollTop: $(hash).offset().top - $("#header.swag-style").height(),
}, 800, function(){
return false;
window.location.hash = newHash;
});
} // End if
});
你可以看到问题,当你在顶部导航点击以下页面:
我曾尝试以下建议的解决方案,没有无济于事。
对不起,这并不适合我。 –