Sullan
Sullan

Reputation: 1157

Animate image opacity from 0 to 100 and back to 0

I have one image which is stacked on top of another one. I am trying to animate the top image opacity to 0 and then back to 100 and then again to 0. This should continue in a loop. Is there a way i can achieve it ?? Please help..

$('.bannerHover').animate({
    opacity: 0.25
  }, 5000, function() {
  });

Upvotes: 0

Views: 465

Answers (1)

Yi Jiang
Yi Jiang

Reputation: 50095

We can create a simple recursive function that calls jQuery's fade function, and when complete, call itself again using the callback supplied by the fade function. With jQuery 1.4.4's fadeToggle function, it can be done as simply as:

var b = $('#block');
function fade(){
    b.fadeToggle(1000, fade);
}
fade();

See: http://www.jsfiddle.net/yijiang/FnBgL/ for a simple example

Upvotes: 1

Related Questions