繁体   English   中英

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

[英]How to scroll to top using JQuery and Material-Design-Lite

我在网站上一直使用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>

有其他解决方法吗? 我试过不使用JQyery,但也没有用。 我正在尝试使用的网站在这里。

这可能是由于主容器,标头的固定位置引起的。 材料设计使用mdl容器中的溢出。 因此,使用此代码滚动顶部:

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

您可以尝试使用

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

您可以使用以下链接进行检查。

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

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

对我来说,它与:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM