[英]Auto bottom scroll div jquery in a MDL framework page
我有关于使用MDL框架在div中滚动的问题
目标 是在4秒钟后滚动到div的底部
这是我的jQuery:
$('#user-select').on('change', function() {
$("html, body").delay(4000).animate({ scrollTop: $(document).height() }, 1000);});
我也试过这个:
$('#user-select').on('change', function() {
setInterval(function() { $('#chat').animate({scrollTop: $('#chat').height()}, 1000); },4000);});
这是我的html:
<div style="width:100%;" id="chat_box">
<div id="chat">
</div>
</div>
div的内容通过AJAX请求加载
最终代码如下所示:
<div style="width:100%;" id="chat_box">
<div id="chat">
<div class="bubble right">
<div class="content">
Test 1</div>
</div>
<div class="bubble left">
<div class="content">
Test 1
</div>
</div>
</div>
</div>
我已经尝试过使用jquery在div中向下滚动的多个选项,但是它们都不起作用
非常感谢!!
我发现了如何:
jQuery的
var scrollTo = function(top) {
var content = $(".mdl-layout__content");
var target = top ? 0 : $(".page-content").height();
content.stop().animate({ scrollTop: target }, 3000);
};
var scrollToTop = function() {
scrollTo(true);
};
var scrollToBottom = function() {
scrollTo(false);
};
并且比4秒后调用该函数
setTimeout(scrollToBottom, 4000)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.