0

I can't figure out how to animate my DIV so that it goes to the #slot1 position (and later any slot I choose).

Here is my javascript code and the fiddle

$(function (){
  $('#deck').click(function (){
    var slotPos = $('#slot1').position();
    $(this).animate({left: slotPos.left}, 400);
  });

});

http://jsbin.com/ejeweb/4/

Thanks in advance!

4

1 回答 1

0
$(#slot1 ).position()

function giving the relative position w.r.t to

<div id='head'>

container. So you can try below code. And use accordingly it:

  $(function (){
  $('#deck').click(function (){
var slotPos = $('#slot1').position(),
       hand=$("#hand").position(); 
   $("#deck").animate({
   left: 10+hand.left+slotPos.left,
   top:10 + hand.top},
   400);
})
}
);

Let me know if this works for you!

于 2013-04-25T14:00:24.237 回答