2011-04-20 99 views
4

我想重複從.animate()開始的鏈接事件(由註釋表示)。寫這個的正確方法是什麼?.each()中的調用函數

$("div").each(function(i, e){ 
    $(this).animate({ left: $(this).parent().width() }, d[i], "linear", 
     function(){ $(this).css({left: -parseInt($(this).css("width")) }) 
     //would like to call function at this stage 
    }); 
})   

這結束了工作:

$("div").each(v = function(i, e){ 
    $(this).animate({ left: $(this).parent().width() }, d[i], "linear", 
     function(){ $(this).css({left: -parseInt($(this).css("width")) }) 
     v(); 
     }); 
    });   

回答

2

喜歡這個?

$("div").each(function(i, e){ 
    $(this).animate({ left: $(this).parent().width() }, d[i], "linear", 
     v = function(i){ 
      $(this).css({left: -parseInt($(this).css("width")) }) 
      if(i == null) v(1); 
     }); 
}) 

不知道我完全理解你的目標......

+0

這只是什麼我需要做的,它幫助我正確地完成的功能。張貼在上面。 – jeffreynolte 2011-04-20 20:07:10