【发布时间】:2016-10-06 18:48:45
【问题描述】:
使用CSS Tricks Smooth Page Scroll 代码,我们刚刚注意到,当您第一次单击导航链接时,它会向下滚动,但不会滚动到应有的程度,大约比预期部分高 700 像素。任何后续点击都可以正常工作,这是奇怪的第一次导航点击。
我已经尝试过 window.load,因为我了解到,在用户第一次点击时,所有页面元素可能都没有加载,但这并没有帮助。
jQuery 版本:1.12.4/jquery.min.js
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
【问题讨论】:
-
我也一样,怎么回事?
标签: javascript jquery css scroll smooth-scrolling