【发布时间】:2015-05-12 14:00:19
【问题描述】:
我想滚动到特定的 div,然后让它在目标 div 之前大约 70 像素处停止。这是我弄下来的教程:
https://css-tricks.com/snippets/jquery/smooth-scrolling/
$(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;
}
}
});
});
【问题讨论】:
-
scrollTop: target.offset().top - 70? -
嗨@rjtkoh,如果您提到您遇到的问题/错误消息,这将改善您的问题 --- 或者至少解释什么不起作用。
标签: javascript jquery jquery-animate autoscroll