4

我创建了一个显示所有行的仪表板,但我想要一个自动滚动,它会慢慢向下滚动页面底部,然后慢慢滚动回顶部并重复。我已经用谷歌搜索了这个并且无法获得工作代码。我一直在寻找 jQuery 代码,但什么都可以。

因为页面会一直调整它不能有固定的高度滚动。

不确定您是否需要更多信息,但如果需要,我会更新这个问题。

问候开局

4

4 回答 4

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);

示例:http: //jsfiddle.net/NaP8D/11/

于 2012-09-18T13:16:29.990 回答
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>

http://jsfiddle.net/neelu/gvvnd0tt/8/

于 2017-04-12T08:51:31.260 回答
1

在这里,这应该很好用,只需将 5000 更改为以 ms 为单位的时间即可调整速度。

http://jsfiddle.net/BDc6S/3/

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"));​
于 2012-09-18T13:28:30.430 回答
-1
function doSomething() {
  $(document).scrollTop($(document).height());
}
setInterval(doSomething, 5000);

这将每 5 秒滚动到页面底部。如果您有像 facebook 这样基于用户滚动的自动加载内容,这将很有用。

于 2015-12-10T16:58:53.917 回答