2013-02-13 86 views
1

我在表格单元格中有一个元素,我必须将其移动到另一个具有慢动画的单元格的方向。我该怎么做。如何在单元格中逐个单元格动画元素?

<table> 
<td .. 

</table> 

看看演示DEMO

我从以前thread

我想通过细胞在表中移动的元素慢慢细胞得到了一些资源?演示中是否有缺失?

+1

非常不可能移动表格单元格。使用绝对定位 – mplungjan 2013-02-13 07:18:22

回答

1

您的小提琴中的代码正常工作,但是由于您在循环中运行动画调用,因此它将快速运行,您或多或少地同时调用所有动画。我改变了一下方法:

$("#move").bind("click",animate); 

var direction=[4,7,8,11] 
function animate(){ 
    // initalize with first element of direction array 
    moveAnimate("#p11",0); 
} 


function moveAnimate(element, count){ 
    if(count >= direction.length) {return; } 
     // set the newParent 
     var newParent = '#pos' + direction[count], 
      element = $(element); //Allow passing in either a JQuery object or selector 

    newParent= $(newParent); //Allow passing in either a JQuery object or selector 
    var oldOffset = element.offset(); 
    element.appendTo(newParent); 
    var newOffset = element.offset(); 

    var temp = element.clone().appendTo('body'); 
    temp.css('position', 'absolute') 
     .css('left', oldOffset.left) 
     .css('top', oldOffset.top) 
     .css('zIndex', 1000); 
    element.hide(); 
    temp.animate({'top': newOffset.top, 'left':newOffset.left}, 'slow', function(){ 
     element.show(); 
     temp.remove(); 
     // increase the counter 
     count++; 
     // call next animation after the current one is finished 
     moveAnimate(element,count); 
    }); 
} 

更新fiddle is here

+0

感谢它正在工作 – user1834809 2013-02-13 08:35:25

相关问题