平滑滚动链接到同一页面断断续续的项目

时间:2016-09-21 22:09:56

标签: javascript jquery wordpress smooth-scrolling

我在wordpress网站上使用jQuery平滑滚动代码,我已将其嵌入在正文</head>标记正上方的标题中。我的主菜单按钮链接到同一页面的各个部分。当我点击这些按钮时,它们跳转到同一页面上的部分,但滚动确实口吃并且非常紧张。然而,当我使用按钮&#34;立即获取6.5驱动程序时,它可以顺利运行!&#34;它不在主菜单中(页面的左上方)。这是代码:

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

它与其他一些代码有冲突吗?有没有人有任何想法?感谢

网站:http://krankgolf.staging.wpengine.com

0 个答案:

没有答案