2017-04-26 156 views
0

我一直在抨击我的头靠在墙上,试图使用大量顺畅的滚动插件来工作,为什么注册按钮无法顺利地向下滚动到#target部分。平滑滚动无法正常工作

请帮助蜂巢介意,我正在使用CSS技巧代码。

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

您可以在

https://codepen.io/samducker/pen/RVoORy

回答

1

看到笔所有的HTML CSS和其他JS取消你的代码,并尝试了这一个(这也许有点快改变它也许500) ,如果你的按钮和主播之间的内容太多,可能会有些滞后:

/*Scroll Down Button*/ 
$(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; 
      } 
     } 
    }); 
}); 
+0

作品一个好心的兄弟,我以前使用的代码如何处理所有css技巧示例,但是在我的页面上不起作用? –

+0

我不知道。也许是一个复制粘贴问题。因为你可以保留你的解决方案,只需将('a [href * =#]:not((href =#])')改为('a [href * =“#”]:not([href =“# “])') – RacoonOnMoon

+0

我不想贪心,但你可以选择与绿色勾号正确的答案。会有帮助的:) – RacoonOnMoon

0

你的jQuery选择器似乎不正确。因此,点击按钮时,点击功能不会触发,并会回退到默认的锚定行为。我叉你的codepen和更改jQuery选择器a请参阅:https://codepen.io/anon/pen/VbmNXd

尝试将jQuery选择器更改为适用于您的应用程序的内容。