0

I want to scroll up to down if no user active on webpage after 10 minutes. How do I write jquery code for it?

I write this code for it-

<script>
 var time = new Date().getTime();
 $(document.body).bind("mousemove keypress", function(e) {
     time = new Date().getTime();
 });

 function refresh() {
     if(new Date().getTime() - time >= 600000) 
       {
           $('html, body').animate({scrollTop: '500px'}, 800);
       }
     else
     { 
         setTimeout(refresh, 600000);
     }
 }

 setTimeout(refresh, 600000);
</script>
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

try like this ......

function refresh() 
 {

 if(new Date().getTime() - time >= 600000) 
   {
        window.scrollTo(0,0);
   }
 else
 { 
     setTimeout(refresh, 600000);
 }
 }

 setTimeout(refresh, 600000);
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Sindhu
  • 473
  • 6
  • 19
0

Using the methods employed on this thread, Detecting user inactivity over a browser - purely through javascript, You can program your own action into the page.

You can use the following to scroll to the top of the page:

$(window).scrollTop(0);

EDIT: Reread and saw you mentioned scroll up to down. You mean snap to the top of the page, then animate a scroll downwards until you reach the bottom of the page? Here you go if that is the case: Modify to suit your needs: http://jsfiddle.net/Fa9xu/2/

Alternatively, you can try your code without single quotes around 500px, and removing px.

Community
  • 1
  • 1
ryanlutgen
  • 2,951
  • 1
  • 21
  • 31