2011-04-20 70 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