水平平滑滚动一页



我一直在构建一个水平的单页网站。在过去的两天里,我尝试了各种不同的方法都没有成功。最后,我想出了如何使平滑的滚动工作。但也不完全是……它会轻微滑动,但不会滑动整个部分。

函数如下:

    $(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

任何帮助都是非常感激的!

最好的,李维

尝试设置'scrollLeft: target.offset() '。Left '代替top

只是一个小小的改变:

$(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().left
        }, 1000);
        return false;
      }
    }
  });
});

最新更新