show-notice
hide-notice

Thursday 15 August 2013

Scroll Page Automatically by few pixels after every few seconds using jQuery


Introduction:

It would be nice feature for web pages if the web page scrolls automatically by few pixels after every 2, 3 or 5 seconds so that the users don't have to scroll it. This is quite useful for webpages having articles, posts, very long text or lengthy pages.


So, In this post you will find jQuery way to "Scroll Page Automatically by few pixels after every few seconds".

For the demo purpose, we will be scrolling the webpage by 200 pixels and after every 2 seconds. To do this, we need to use JavaScript "setInterval" method, which is responsible for calling a function/particular code after x seconds. So in this case, it would be 2 seconds.

Then, all you want is to get window scrollTop value and add 200 to it and then just scroll it.. Simple and Easy!!!!! 

Example:
$(document).ready(function () {
    setInterval(function () {
        var iScroll = $(window).scrollTop();
        iScroll = iScroll + 200;
        $('html, body').animate({
            scrollTop: iScroll
        }, 1000);
    }, 2000);
});

SHARE THIS POST   

0 comments :

Post a Comment

Design by Gohilinfotech | www.gohilinfotech.blogspot.com