该网站有一个可平滑滚动的 div
:
http://fatlinesofcode.github.io/jquery.smoothwheel/demo/smoothwheel.html
但是我怎样才能在整个body
而不是div
上实现平滑滚动呢?
最佳答案
你可以使用这样的东西:
$(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;
}
}
});
});
并且它将平滑滚动整个页面,而不是特定的 div
。其主要症结在于:
$('html,body').animate({
scrollTop: ...
}, 1000);
有关更多信息,请查看文章:Smooth Scrolling .
关于javascript - jQuery 整体平滑滚动而不是 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34548761/