Ad Space
Cloud Computing and Cloud Hosting by Rackspace
Ad Space
Cloud Computing and Cloud Hosting by Rackspace

Hosting Geared For
your CMSMS needs

CMSMS ready Hosting

Hosting Starting at $15

  • • Hosted Mail
  • • Personal Control Panel
  • • CMSMS 1.8.1 tested
  • • Lightly packed servers
  • • Intrusion Detection
  • • URL monitored
  • • Custom solutions available

Order your hosting Now

CP Blogs

Use multiple timers in parallel

Posted by: Jeremy Bass
on Jun 28, 2010

Category:

javascript, snippets, Coding, Intermediate, jQuery, CMS Made Simple

Summary:

So you need to run a parallel timers? More to keep record of the code for later :D


Ad Space

The goal is not to tie to the ids.. that is just here out of convenience

timer1

stoped


timer2

stoped

Standalone test
 

// 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.

Ad Space

Get Social With It

[+]

Add A Comment

[+]

Code in the picture:
Title:
Your Name(*):
Email:
Notify me of any further comments to this thread:
Website:
Comment(*):
 
Previous page: Hosting FAQ Next page: Experimental