![](/img/trans.png)
[英]Material Design Lite and jQuery, smooth scroll not working
[英]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() > 200) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
$('#back-to-top').hide().click(function() {
$('html, body').animate({scrollTop:0}, 600);
return false;
});
</script>
有其他解決方法嗎? 我試過不使用JQyery,但也沒有用。 我正在嘗試使用的網站在這里。
這可能是由於主容器,標頭的固定位置引起的。 材料設計使用mdl容器中的溢出。 因此,使用此代碼滾動頂部:
$(".mdl-layout__content").animate({scrollTop:0}, 500, "slow");
您可以嘗試使用
$('.mdl-layout__content').animate({scrollTop:0}, 'slow');
您可以使用以下鏈接進行檢查。
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.