水平平滑滚动一页

时间:2015-10-09 15:45:46

标签: jquery html css

我一直在建立一个水平的单页网站。在过去的两天里,我一直在尝试各种不同的事情而没有运气。最后,我想出了如何使平滑滚动工作。但不完全..它略微滑过,但它不会滑动整个部分。

这是功能。

    $(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) {
                $('body').animate({
                  scrollLeft: target.offset().top
                }, 1000);
                return false;
              }
            }
          });
        });

可以在levistroop.com/test找到完整的网站

非常感谢任何帮助!!

最佳, 列维

1 个答案:

答案 0 :(得分:1)

尝试设置'scrollLeft:target.offset()。left'而不是top

相关问题