Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Slow down setinterval after a while
Old 02-09-2009, 07:12 PM Slow down setinterval after a while
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Is there a way to slow down a setInterval after certain amount of time?

I have a shoutbox and certain other things that auto-refresh after about 10 seconds. I'm wondering if there's a way for it to work like so:

The user loads the page, setInterval works at refreshing the shoutbox every 10 seconds. If the user's been on the page for 5 minutes with NO activity (such as posting a message in the shoutbox) then setInterval slows down to ... say... 1 minute.. and if inactive for say 30 minutes, then it slows down to every 10 minutes, and if inactive for 3 hours, then stop loading altogether.

I use jQuery and the code is like this:

Code:
$('#shoutbox').load('ajax/shoutbox.php', function(){
                                                                                            $('#shoutbox').fadeIn("fast")
                                                                                            });
setInterval(function(){$('#shoutbox').load('ajax/shoutbox.php')}, 10000);
Any suggestions?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 02-10-2009, 02:08 AM Re: Slow down setinterval after a while
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Assign the Interval to a variable and after a certain amount of time, clear the old Interval, and assign the new one to that same variable.

Code:
intval=setInterval(...,...);

if(time blahblah){
    clearInterval(intval);
    intval=setInterval(...,...);
}
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Slow down setinterval after a while
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17883 seconds with 12 queries