Created
September 11, 2010 18:11
-
-
Save rainux/575409 to your computer and use it in GitHub Desktop.
Simple jQuery().draggable() plugin via http://www.coderholic.com/jquery-draggable-implementation/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.draggable = function() { | |
var move = $.proxy(function(event) { | |
if (this.data('mouseMove')) { | |
var changeX = event.pageX - this.data('mouseX'); | |
var changeY = event.pageY - this.data('mouseY'); | |
var newX = parseInt(this.css('left')) + changeX; | |
var newY = parseInt(this.css('top')) + changeY; | |
this.css('left', newX); | |
this.css('top', newY); | |
this.data('mouseX', event.pageX); | |
this.data('mouseY', event.pageY); | |
} | |
}, this); | |
this.mousedown($.proxy(function(event) { | |
this.data('mouseMove', true); | |
this.data('mouseX', event.pageX); | |
this.data('mouseY', event.pageY); | |
}, this)); | |
this.mouseup($.proxy(function() { | |
this.data('mouseMove', false); | |
}, this)); | |
this.mouseout(move); | |
this.mousemove(move); | |
return this; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment