我创建了一个回显所有行的仪表板,但我想要一个自动滚动,它将慢慢向下滚动页面底部,然后慢慢滚动回到顶部并重复。我用Google搜索了这个,但无法获得正常工作的代码。我一直在寻找jQuery代码,但任何事情都可以。
因为页面会一直调整,所以无法固定高度滚动。
不确定您是否需要更多信息,但如果您这样做,我将更新此问题。
此致 开局
答案 0 :(得分:9)
你可以使用这样的东西。
//run instantly and then goes after (setTimeout interval)
$("html, body").animate({ scrollTop: $(document).height() }, 4000);
setTimeout(function() {
$('html, body').animate({scrollTop:0}, 4000);
},4000);
var scrolltopbottom = setInterval(function(){
// 4000 - it will take 4 secound in total from the top of the page to the bottom
$("html, body").animate({ scrollTop: $(document).height() }, 4000);
setTimeout(function() {
$('html, body').animate({scrollTop:0}, 4000);
},4000);
},8000);
//Use this to stop the scroller -> clearInterval(scrolltopbottom);
答案 1 :(得分:2)
你应该试试这个以获得更好的结果
//run instantly and then goes after (setTimeout interval)
$("html, body").animate({ scrollTop: $(document).height() }, 4000);
setTimeout(function() {
$('html, body').animate({scrollTop:0}, 4000);
},4000);
setInterval(function(){
// 4000 - it will take 4 secound in total from the top of the page to the bottom
$("html, body").animate({ scrollTop: $(document).height() }, 4000);
setTimeout(function() {
$('html, body').animate({scrollTop:0}, 4000);
},4000);
},8000);
$('html, body').mouseover(function(e) {
$(this).stop(true);
}).mouseout(function() {
$(this).stop(false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div style="height:2000px; float:left; width:100%;">
Text text
Text text
Text text
Text text
Text text
Text text
Text text
Text text
Text textv
Text text
Text text
Text text
Text textText text
Text textText text Text textText text
Text textText text Text textText text Text textText text Text textText text Text textText text
<p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p>Text textText text
<p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p>
<p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p> <p>
Text textText text Text textText text Text textText text Text textText text Text textText text
</p>
</div>
答案 2 :(得分:1)
在这里,这应该运作良好,只需将5000改为以ms为单位的时间来调整速度。
function scrollDown(el) {
el.animate({
scrollTop: el[0].scrollHeight
}, 5000, function() {
scrollUp(el)
});
};
function scrollUp(el) {
el.animate({
scrollTop: 0
}, 5000, function() {
scrollDown(el);
});
};
scrollDown($("html,body"));
答案 3 :(得分:0)
function doSomething() {
$(document).scrollTop($(document).height());
}
setInterval(doSomething, 5000);
这将每5秒滚动到页面底部。如果您有基于用户滚动的自动加载内容(如facebook),这将非常有用。