javascript - How to fade images at different times with jQuery -
i have 2 different images classed (letterfile , handfile). want 1 fade out other fades in , keep going that.
this have, fading images @ same time:
$( document ).ready(function() { setinterval(function() { $( ".letterfile" ).fadetoggle( "slow", "linear" ); settimeout(function(){ $( ".handfile" ).fadetoggle( "slow", "linear" ); }, 2000); }, 2000); });
any suggestions?
you have issue because right after first iteration show both of them , there onwards toggles state, i.e both visible or not visible. can rid of timeouts etc , make more generic.
give common class images(or divs or ever using)
<img class="letterfile slide" src="http://placehold.it/100x100" /> <img class="handfile slide" src="http://placehold.it/200x200" />
js
$(document).ready(function () { var duration = 'slow', type="linear"; function toggleem() { //get visible slide , after 2 sec start fade out transition $('.slide:visible').delay(2000).fadeout(duration, type, function(){ //once complete slide in next one, i.e sibling of image $(this).siblings('.slide').fadein(duration, type, function(){ toggleem(); //after completed start loop again }); }) } toggleem(); });
most animation methods have comple callback wil l executed when 1 animation completed , preciesly in case want start next fadetransition.
Comments
Post a Comment