Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging div styles using a javascript timer with different intervals
    primarykey
    data
    text
    <p>Currently I have the following code creating my timer:</p> <pre><code>&lt;script type="text/javascript"&gt; var interval; var minutes = 8; var seconds = 10; function countdown(element) { interval = setInterval(function() { var el = document.getElementById(element); if(seconds == 0) { if(minutes == 0) { alert(el.innerHTML = "countdown's over!"); clearInterval(interval); return; } else { minutes--; seconds = 60; } } if(minutes &gt; 0) { var minute_text = minutes + (minutes &gt; 1 ? ' minutes' : ' minute'); } else { var minute_text = ''; } var second_text = seconds &gt; 1 ? 'seconds' : 'second'; el.innerHTML = minute_text + ' ' + seconds + ' ' + second_text + ' remaining'; seconds--; }, 1000); } &lt;/script&gt; </code></pre> <p>And I use the following buttons to trigger it:</p> <pre><code>&lt;input type="button" onclick="countdown('countdown');" value="Start" /&gt; &lt;input type="button" onclick="clearInterval(interval);" value="Pause" /&gt; </code></pre> <p>How can I track the timer and change page styles as time goes by?</p> <p>For example, when I click start I want to highlight one div, after 5 seconds I want to highlight another div and unhighlight the first, 20 seconds after that I want to change the highlight again, 10 seconds after that I change the highlight again, and so on. </p> <p>The intervals should be able to be different times, but most cases will follow the pattern above (0, 5, 5, 20, 10, 20, 10, 20, 10...) so that's a good starting place. The total length of the timer is always 8 minutes, so the intervals can be hard coded and I could use PHP to select the correct code (although inefficient, probably easiest).</p> <p>Anyone have any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload