1

Following is the fiddle: jsfiddle

The intitial HTML: code is as below, refer fiddle for javascript code:

<div id="test_time_left">Time Left :<b><span id="time_value" style="padding-left:5px;"></span> </b> </div>

Now I want to change the font color to red and blink the whole timer only when the timer reaches to value 00:05:00. Till then nothing from the timer should get blink or should have red font color. Now the second colon(after min:) is getting blinked from start and only the min value is getting the font color red. Can anyone help me in removing the bugs I've made in the fiddle and correct the functionality? Thanks in advance. Waiting for your answers.

3
  • you could use this: if(time=="05"){document.getElementById("myid").style.color="#ff0000";} w3schools.com/jsref/prop_style_color.asp Commented Feb 4, 2014 at 19:12
  • Only when minute is 05 and second is 00 or only when minute is 05 and second is any value? Commented Feb 4, 2014 at 19:14
  • @artur99:the red color and blinking should start when the timeer is 00:05:00 till it becomes 00:00:00. That is till the end. Commented Feb 4, 2014 at 19:15

2 Answers 2

2

Change line 40 to this:

if(mins <= 5) {document.getElementById("time_value").style.color="#ff0000";};

http://jsfiddle.net/RJdwh/4/

This will change the color of the <span id="time_value">. More about colors in js: http://www.w3schools.com/jsref/prop_style_color.asp

Last revision: http://jsfiddle.net/RJdwh/7/

Sign up to request clarification or add additional context in comments.

7 Comments

the color of everything is changed to red but the second colon still blinking from start which shouldn't be. And the second thing is when timer reaches 00:05:00 everything should get red and blink. Now everything is getting red but not blinking. SO can you please made some corrections to the fiddle in order to make this happen?
Still it's not done. The second colon is blinking befor timer reaches 00:05:00 and after that nothing is blinking. Actually from 00:05:00 everything has to blink including timer values as well as two colons.
yes it's working but it has still two small issues. First one is the second colon is still blinking befor the timer reaches the value 00:05:00 which should not and the second correction is the duration between blinking is of 2 seconds it should be one second. Other than these everything is as expected. Can you please modify your code to correct these two issues?
Do you have skype or Gtalk? Give me your id, we would talk easier. So, you want all to blink when mins is 5 or less and not blinking at all when it is 6 ?
So, do you have any Skype or GTalk id? or give me your email
|
1

is this what yre you looking for:

http://jsfiddle.net/RJdwh/10/

Function.prototype.Timer = function (interval, calls, onend) {
  var count = 0;
  var payloadFunction = this;
  var startTime = new Date();
  var callbackFunction = function () {
    return payloadFunction(startTime, count);
  };
  var endFunction = function () {
    if (onend) {
      onend(startTime, count, calls);
    }
  };
  var timerFunction =  function () {
    count++;
    if (count < calls && callbackFunction() != false) {
      window.setTimeout(timerFunction, interval);
    } else {
      endFunction();
    }
  };
  timerFunction();
};

function leadingzero (number) {
    return (number < 10) ? '0' + number : number;
}
function countdown (seconds, target) {
  var element = document.getElementById(target);
  var calculateAndShow = function () {
    if (seconds > 0) {
      var h = Math.floor(seconds / 3600);
      var m = Math.floor((seconds % 3600) / 60);
      var s = seconds % 60;
        if(seconds <= 300 ){
             element.style.color ="#FF0000";
            if((seconds%2)>0){
               element.style.color ="#FFFFFF";                
            }
        }
      element.innerHTML='<span>'+
        leadingzero(h) + ':' +
        leadingzero(m) + ':' +
        leadingzero(s)+'</span>';
      seconds--;
    } else {
      return false;
    }
  };
  var completed = function () {
    element.innerHTML = "<strong>Liftoff!<\/strong>";
  };
  calculateAndShow.Timer(1000, Infinity, completed);
}


  new countdown(305, 'time_value');

1 Comment

It blinks once in 2 seconds. He wanted to blink every second, like here: jsfiddle.net/RJdwh/7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.