Moved div on jQuery

[javascript]
var mover = false;
var currx = 0;
var curry = 0;
$(".calculator .title").mousedown(function(eventObject){
mover = true;
currx = eventObject.pageX;
curry = eventObject.pageY;
});

$(window).bind(‘mousemove’, function(eventObject) {
if(!mover)
return;

var obj = $(".calculator");
mouseX = eventObject.pageX;
mouseY = eventObject.pageY;
x = obj.position().left;
y = obj.position().top;
obj.css({
left: x + (mouseX-currx),
top: y + (mouseY-curry),
});
currx = eventObject.pageX;
curry = eventObject.pageY;
});

$(".calculator .title").mouseup(function() {
mover = false;

});
[/javascript]

Leave a Reply