2011-02-12 71 views
1

我正在创建一个匹配游戏。游戏使用jQuery可以正常工作,但我想要做的是让牌从屏幕上的网格位置移动(飞行)到“发现”堆。这可以使用jQuery完成吗?jQuery移动图像

我目前有使用表格创建的网格。

任何帮助将不胜感激。

詹姆斯:-)

回答

2

是的!

//Call this function on the $img object you want to animate 
function match_found($img) { 
    $animator = $img.clone(); 
    $animator 
     .css({position: 'absolute', margin: 0 }) 
     .offset({top: $img.offset().top, left: $img.offset().left}) 
     .appendTo("body") 
    ; 
    $img.remove(); 
    $found_pile = $("#found-pile"); 
    $animator 
     .animate({top: $found_pile.offset().top, left: $found_pile.offset().left }); 
} 
+0

谢谢。这工作得很好。 – 2011-02-13 11:53:48

0

试试这个:

,你可以得到 http://jqueryui.com/demos/position/

不知道你怎么会在一个表中做到这一点的位置,也许把卡片放在一个div中,并在动画之前将位置设置为绝对位置。然后将它设置为动画,然后在你想要的单元格内设置该div。这将是一系列事件,如animate()。appendTo()等。

但是,这可能会让你开始,除非有人知道一个更好的主意。