javascript - loop jQuery simple animated lines 3 times -
update: due vagueness of question - resulted in broad answer doesn't apply (as can see below). full question , problem migrated -- > add loop function around 3 small animations within larger animation functions
how define below loop / play 3 times in row before stopping (simple line animation jquery):
my animation works.. it's 3 lines come out 1 @ time draw triangle... it's looping 3 times need.
var padding = $('.conn-1').css('padding'); var line_anim = 700; $('.replay').hide(); $('.conn-1').width('100%').animate({'height':'100%'},line_anim, function () { $('.conn-2').height('100%').animate({'width':'100%'}, line_anim, function () { $('.conn-3').css({width:'100%'}).animate({'height':'100%'}, line_anim, function(){replay();}) } ); } ); //$('.conn-2').width(0).siblings('.connect-lines').css('margin',0); }, 2000); }); },5000); }
updated code via answered suggestions -- below didn't run / work looping; additional thoughts?
function animall(remainingloops){ if(!remainingloops) return; $('.replay').hide(); $('.conn-1').width('100%').animate({'height':'100%'},line_anim, function () { $('.conn-2').height('100%').animate({'width':'100%'}, line_anim, function () { $('.conn-3').css({width:'100%'}).animate({'height':'100%'}, line_anim, function(){ animall(remainingloops-1); // replay();}) }); }); } ); } ); //$('.conn-2').width(0).siblings('.connect-lines').css('margin',0); }, 2000); }); },5000); }
function animall(remainingloops){ if(!remainingloops) return; $('#blue').width(50).animate({width: '100%'}, function(){ $('#red').width(50).animate({width: '100%'}, function(){ $('#green').width(50).animate({width: '100%'}, function(){ animall(remainingloops-1); }); }); }); } animall(3);
div{height:50px;background:#00f}#red{background:red}#green{background:green}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div id="blue"></div> <div id="red"></div> <div id="green"></div>
Comments
Post a Comment