Hosting Geared For
your CMSMS needs
Hosting Starting at $15
- • Hosted Mail
- • Personal Control Panel
- • CMSMS 1.8.1 tested
- • Lightly packed servers
- • Intrusion Detection
- • URL monitored
- • Custom solutions available
CP Blogs
Use multiple timers in parallel
Category:
javascript, snippets, Coding, Intermediate, jQuery, CMS Made Simple
So you need to run a parallel timers? More to keep record of the code for later :D
Ad Space
timer1
stoped
timer2
stoped
// JavaScript Document var timers_arr = new Array(); function stopCount(timer,status){ /// clear the time from timer clearTimeout(timers_arr[timer]); /// Make sure it's clear //timers_arr[timer]=setTimeout(function(){},0); timers_arr[''+timer+'']=0; jQuery('#'+status).text(timer+' stopped'); } function reportEditStatus(){ jQuery('#timer1_status').text("timer clicked"); timer='timer1'; status='timer1_status'; stopCount(timer,status); /// to test if timer if in array this creats a loop if(timers_arr[timer]==0){ timers_arr[timer]=setTimeout(function(){reportEditStatus()},50); jQuery('#'+status).text("timer started -- reportEditStatus"); /// this is to be clear the loop is working var wid=jQuery('#t1').width(); jQuery('#t1').width(wid+1); } } function resetHighlite(){ jQuery('#timer2_status').text("timer clicked"); timer='timer2'; status='timer2_status'; stopCount(timer,status); /// to test if timer if in array this creats a loop if(timers_arr[timer]==0){ timers_arr[timer]=setTimeout(function(){resetHighlite()},50); jQuery('#'+status).text("timer started -- resetHighlite"); /// this is to be clear the loop is working var wid=jQuery('#t2').width(); jQuery('#t2').width(wid+1); } } $(document).ready(function(){ jQuery('#timer1').toggle(function() { reportEditStatus(); },function() { stopCount('timer1','timer1_status'); }); jQuery('#timer2').toggle(function() { resetHighlite(); },function() { stopCount('timer2','timer2_status'); }); });
Now this is a little overkill if you just need to and don't need to stop it ever and or not a loop. This is more of a test aswell.. But I don't want to lose the code.














Get Social With It
[+]Add A Comment
[+]