JQuery Div not animating in click function
- by Doug
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!!