2011-02-12 56 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()等。

但是,這可能會讓你開始,除非有人知道一個更好的主意。