【问题标题】:Horizontal Smooth Scroll One Page水平平滑滚动一页
【发布时间】:2015-10-09 15:45:45
【问题描述】:

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

这是函数。

    $(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;
              }
            }
          });
        });

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

非常感谢任何帮助!

最好, 列维

【问题讨论】:

  • 尝试设置 'scrollLeft: target.offset().left' 而不是 top。
  • 完美!!我完全错过了。非常感谢。
  • @GreggDuncan 您可以将其设置为信用答案。

标签: jquery html css


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    只是一个小改动:

    $(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;
          }
        }
      });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多