JQuery Div not animating in click function

Posted by Doug on Stack Overflow See other posts from Stack Overflow or by Doug
Published on 2010-06-13T23:31:41Z Indexed on 2010/06/13 23:42 UTC
Read the original article Hit count: 196

Filed under:
|

Hi Everyone!

I have the following code, I am attempting to have a div animate on a click event, but for some reason the div is immediately moving to the location and it's not animating to the coordinates specified, what am I doing wrong here? code:

  $(document).ready(function() {
    $('#example1').click(function(e){
        var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
        $('#example1-xy').html("X: " + x + " Y: " + y);
        var leftOfShip = x;                                              
        //var leftOfShip = document.getElementById("ship").style.left + 20;
        $("#ship").animate({left: $("#ship").css("left",leftOfShip)},5000);
    });
  });

Any Advice would be of help!!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about click