自动滚动到页面底部,然后滚动到顶部并重复 [英] Autoscroll to bottom of page then top and repeat

查看:89
本文介绍了自动滚动到页面底部,然后滚动到顶部并重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个仪表板,该仪表板回显了所有行,但是我想要一个自动滚动,该滚动将缓慢向下滚动到页面底部,然后缓慢滚动回到顶部并重复.我已经用谷歌搜索了,无法获得有效的代码.我一直在寻找jQuery代码,但一切都会做.

I have created a dashboard which echos out all the rows but I want an auto scroll which will slowly scroll down the bottom of the page and then scroll slowly back to the top and repeat. I have googled this and can't get a working code. I have been looking for jQuery codes but anything will do.

因为该页面将在无法固定高度滚动的所有时间进行调整.

Because the page will adjust all the time it cant have fixed height scroll.

不确定是否需要更多信息,但如果需要,我将更新此问题.

Not sure if you need more information but if you do I will update this question.

问候 甘比特

推荐答案

您可以使用类似这样的东西.

You could use something like this.

//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/

这篇关于自动滚动到页面底部,然后滚动到顶部并重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆