Javascript jQuery在整个主体上平滑滚动,而不是在DIV上

Javascript jQuery在整个主体上平滑滚动,而不是在DIV上,javascript,jquery,html,css,Javascript,Jquery,Html,Css,本网站有一个平滑滚动的div: 但是我如何才能使整个主体平滑滚动,而不是div?您可以使用以下内容: $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {

本网站有一个平滑滚动的
div


但是我如何才能使整个
主体
平滑滚动,而不是
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);

有关更多信息,请参阅文章:。

如果您计划使用您引用的jQuery扩展:查看源代码,您只需调用文档上的smoothWheel函数,而不是div

()

初始化:

$(document).smoothWheel()
$(document).smoothWheel({'remove':true})
禁用功能:

$(document).smoothWheel()
$(document).smoothWheel({'remove':true})
演示:

$(document).smoothWheel()
$(document).smoothWheel({'remove':true})

我想你误解了我的问题。我希望平滑的滚动始终出现在整个页面上,而不是在点击锚定链接时。@Jasoneclau仍然不清楚上面所说的内容。对不起,英语不是我的母语,我觉得很难解释。这个wordpress主题具有我想要的效果()。卷轴和它的非常顺利。我也想要那种效果。@jasoneclau-Ha。这样更好。@Jasoneclau只需将此脚本添加到您的页面好友中即可。这就是他们所使用的。