如何使用JQuery和Material-Design-Lite滚动到顶部

问题描述 投票:2回答:4

我一直在我的网站上使用Material-Design-Lite,我也使用JQuery来显示滚动到顶部的按钮。但他们没有合作。安装了Material-Design-Lite后,该按钮在点击时不执行任何操作。

<div class='back-to-top'>
  <a class='hvr-icon-spin' href='#'/>
</div>

<script>
  $(window).scroll(function() {
    if($(this).scrollTop() &gt; 200) {
      $(&#39;#back-to-top&#39;).fadeIn();
        } else {
        $(&#39;#back-to-top&#39;).fadeOut();
        }
        });
      $(&#39;#back-to-top&#39;).hide().click(function() {
        $(&#39;html, body&#39;).animate({scrollTop:0}, 600);
        return false;
        });
</script>

有没有其他方法可以解决它?我试过不使用JQuery,但它也没有用。我正在尝试使用它的网站是qazxsw poi

javascript jquery css material-design-lite
4个回答
2
投票

这可能是由于主容器,标题的固定位置而发生的。材料设计在mdl容器中使用溢出。所以使用此代码滚动顶部:

here.

1
投票

你可以尝试使用

$(".mdl-layout__content").animate({scrollTop:0}, 500, "slow");

0
投票

您可以通过以下链接查看。

$('.mdl-layout__content').animate({scrollTop:0}, 'slow');

http://jsfiddle.net/6qrQF/88/

0
投票

对我来说它适用于:

 jQuery(document).ready(function() {
  //set the link
  jQuery('#top-link').topLink({
    min: 500,
    fadeSpeed: 100
  });
  //smoothscroll
  jQuery('#top-link').click(function(r) {    
    jQuery("html, body").animate({ scrollTop: 0 }, 300);
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.