2011-06-21 27 views
0

我有以下的jQuery代码:jquery的缩放效果很慢?

$(document).ready(function() { 


    $('.box').click(function(){ 

     var selectedBox = $(this), 
      selectedBoxLocationX = selectedBox.offset().left, 
      selectedBoxLocationY = selectedBox.offset().top; 

     selectedBox.animate({left:-selectedBoxLocationX, top:-selectedBoxLocationY},600).addClass('current'); 


     otherBoxes = $('.box:not(.current)'); 

     otherBoxes.animate({left:2000},600); 
     selectedBox.effect('scale', {percent:500, direction: 'vertical'}, 1000); 


     selectedBox.click(function(){ 
      selectedBox.effect('scale', {percent:20, direction: 'vertical'},200); 
      otherBoxes.animate({left:0},600); 
      selectedBox.animate({top: 0, left: 0},700).removeClass('current'); 

     }); 

    }); 

}); 

我发现了selectedBox规模的20%是在踢很慢它实际上是扩展的selectedBox动画后

谁能告诉我为什么会发生这种情况?

MTIA!

+0

你能提供jsfiddle的例子吗? – Niklas

+0

谢谢Niklas - http://jsfiddle.net/sk62Y/ – circey

回答

1

我更新您的拨弄(希望)工作示例:

http://jsfiddle.net/sk62Y/4/

你的问题是,一旦你selectedBox.click处理,你有包装盒上的2个click事件。不知何故,这完全混淆了动画。

我现在只需在点击选择框元素时移除原始点击处理程序,然后在第二次点击时重新附加它。

+0

非常棒!谢谢 :-) – circey