Reputation: 45
I have a question, lets say if I have a object and I want it to glow continuously, is this achievable with Jquery? Is there an auto animation function that will loop the fadeIn fadeOut comment? If there is, means I just need two image and toggle fadeIn fadeOut automatically, is there a way to achieve this?
Upvotes: 1
Views: 980
Reputation: 181
You can use setInterval
function to make loop. One interval must be eqaul the sum of fadeOut
and fadeIn
animations. For example:
setInterval( function() {
$( '#comment' ).fadeOut( 800 ).fadeIn( 200 );
}, 1000 );
Upvotes: 0
Reputation: 206689
Let's say you create a DIV
with background image and inside you put the IMG
to fade:
<div class="fade" style="width:100; height:100; background:url(img1.jpg);">
<img src="img2.jpg" />
</div>
than you can use the .fadeTo()
callback to loop the fade of your image:
var opac=[1, 0.2], c=0;
(function loop(){
$('.fade img').fadeTo(400, opac[++c%2], loop);
})();
Upvotes: 1