Monday, 14 September 2015

javascript automatically scroll html page down and up, up and down

There is a solution:

http://stackoverflow.com/questions/8107251/automatically-scroll-page-from-top-to-bottom-then-back-up-and-repeat

My solution is better:

1. you can scroll a specific element.
2. after scrolling down to the bottom it will stay for a while (speed/4).
3. after scrolling up to the top, it will stay for a while (speed/4).




<div id="auto-scrolling-win" ng-include="'app/views/1.1.main.applist.html'"></div>

<script type="text/javascript">
function scroll(speed) {
if ($("#auto-scrolling-win").length >0) {
$("html, body").animate({ scrollTop: $(document).height() - $(window).height() }, speed, function() {
setTimeout( function(){$("html, body").animate({ scrollTop: 0 }, speed);}, speed/4 );
     
   });
};
}

speed = 2000;

scroll(speed)
setInterval(function(){scroll(speed)}, speed * 2 + speed /2);

</script>









No comments:

Post a comment