javascript - How to insert a callback function correctly so as to let one function end and then execute another -


i have simple slider jscript hovers thumbnails left or right depending on button click.

<script> $(document).ready(function() { $(".right-arrow").click(function(){ $(".box1").animate({right:"1100px"},800); $(".box2").animate({right:"1100px"},1000); $(".box3").animate({right:"1100px"},1200); $(".box4").animate({right:"1100px"},1400); $(".box5").animate({right:"1100px"},1600); $(".box6").animate({right:"1100px"},1800); $(".box7").animate({right:"1100px"},2000); $(".box8").animate({right:"1100px"},2200); $(".box9").animate({right:"1100px"},2400); $(".box10").animate({right:"1100px"},2600); $(".box11").animate({right:"1100px"},2800); $(".box12").animate({right:"1100px"},3000); }); $(".left-arrow").click(function(){   $(".box12").animate({right:"0px"},800); $(".box11").animate({right:"0px"},1000); $(".box10").animate({right:"0px"},1200); $(".box9").animate({right:"0px"},1400); $(".box8").animate({right:"0px"},1600); $(".box7").animate({right:"0px"},1800); $(".box6").animate({right:"0px"},2000); $(".box5").animate({right:"0px"},2200); $(".box4").animate({right:"0px"},2400); $(".box3").animate({right:"0px"},2600); $(".box2").animate({right:"0px"},2800); $(".box1").animate({right:"0px"},3000); }); });  </script> 

however if click right button , click left 1 congestion of thumbnails 'colliding' 1 another.

how insert nice callback function wait animation 1 side finished , proceed other way ?

first of all, when see patterns in code, indication should start refactoring:

$(document).ready(function() {      $(".right-arrow").click(function(){         (i = 1; < 13; i++){             $('.box' + i).stop().animate({                 right: 1000             }, {                 duration: 600 + (i * 200),                  queue: true             });         }     });     $(".left-arrow").click(function(){         (i = 1; < 13; i++){             $('.box' + i).stop().animate({                 right: 0             }, {                 duration: 3200 - (i * 200),                 queue: true             });         }     }); } 

regarding timing conflict, need pass true queue option, ensure ensuing animations start after previous ones have completed.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -