在.each()内调用函数

时间:2011-04-20 19:54:16

标签: javascript jquery

我想从内部重复从.animate()开始的链式事件(由注释表示)。写这个的正确方法是什么?

$("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();
      });
   });          

1 个答案:

答案 0 :(得分: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);
        });
})   

不确定我完全理解你的目标......

相关问题