Question

i want to give blink effect to an element by using addClass and removeClass 3 times each i tried this

$("#div").addClass("orange").delay(300).queue(function(next){
    $(this).removeClass("orange");
    next();
});

this is works just 1 time

how can i make this happened 3 times with 300 ms delay?

Was it helpful?

Solution

Just count to three:

(function() {
  var count = 0, $div = $('#div'), interval = setInterval(function() {
    if ($div.hasClass('orange')) {
      $div.removeClass('orange'); ++count;
    }
    else
      $div.addClass('orange');

    if (count === 3) clearInterval(interval);
  }, 300);
})();

You could get fancy and write your own animation plugin for it, I guess.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top