function animation() { var delay_arr = new Array(0.0,1.3,7.1,5.2); var curr_start = delay_arr[Math.floor(Math.random()*4)]; if(curr_start <= delay_arr[0]){ $('#tween1').css( { display:'inline', opacity:0.5 } ); $('#tween1').animate( { left:820, opacity:0.12, width:76 }, 5600, function(){ $('#tween1').css( { width:162, left:-171 } ); } ); } if(curr_start <= delay_arr[1]){ var del1 = delay_arr[1] - curr_start; $('#tween2').css( { display:'inline', opacity:0.0 } ); $('#tween2').delay(del1*1000); $('#tween2').animate( { left:-291, opacity:0.2, width:286 }, 4200, function(){ $('#tween2').animate( { left:815, opacity:0.2, width:60 }, 4500, function(){ $('#tween2').css( { width:119, left:837 } ); } ); } ); } if(curr_start <= delay_arr[2]){ var del2 = delay_arr[2] - curr_start; $('#tween3').css( { display:'inline', opacity:0.0 } ); $('#tween3').delay(del2*1000); $('#tween3').animate( { left:-55, opacity:0.2, width:995 }, 4100, function(){ $('#tween3').animate( { opacity:0.0 }, 1800, function(){ $('#tween3').css( { width:146, left:395 } ); }); } ); } var del4 = 9.1 - curr_start; $('#tween4').css( { display:'inline', opacity:0.0 } ); $('#tween4').delay(del4*1000); $('#tween4').css( { opacity:0.15 } ); $('#tween4').animate( { left:-271, opacity:0.3, width:270 }, 4400, function(){ $('#tween4').css( { width:75, left:834 } ); animation(); }); var del5 = 10.2 - curr_start; $('#tween5').css( { display:'inline', opacity:0.0 } ); $('#tween5').delay(del5*1000); $('#tween5').css( { opacity:0.15 } ); $('#tween5').animate( { left:816, width:0 }, 2800, function(){ $('#tween4').css( { width:76, left:-105 } ); }); if(curr_start <= delay_arr[3]){ var del6 = delay_arr[3] - curr_start; $('#tween6').css( { display:'inline', opacity:0.0 } ); $('#tween6').delay(del6*1000); $('#tween6').css( { opacity:0.1 } ); $('#tween6').animate( { left:-47 }, 4800, function(){ $('#tween6').css( { width:45, left:818 } ); }); } } $(document).ready( animation );