Автопрокрутка к нижней части страницы, затем к началу и повтор
Я создал панель мониторинга, которая выводит все строки, но мне нужна автопрокрутка, которая будет медленно прокручиваться вниз по нижней части страницы, а затем медленно прокручиваться обратно к началу и повторяться. Я гуглил это и не могу получить рабочий код. Я искал коды JQuery, но все будет делать.
Поскольку страница будет корректироваться все время, она не может иметь фиксированную высоту прокрутки.
Не уверен, если вам нужна дополнительная информация, но если вы сделаете это, я обновлю этот вопрос.
С уважением Гамбит
4 ответа
Вы могли бы использовать что-то вроде этого.
//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);
Пример: http://jsfiddle.net/NaP8D/11/
Вы должны попробовать это для лучшего результата
//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>
Здесь это должно работать хорошо, просто измените 5000 на время в мс, чтобы отрегулировать скорость.
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"));
function doSomething() {
$(document).scrollTop($(document).height());
}
setInterval(doSomething, 5000);
Это будет прокручивать вниз страницы каждые 5 секунд. Это будет полезно, если у вас есть автоматическая загрузка контента на основе пользовательской прокрутки, такой как Facebook.