Skip to content

Instantly share code, notes, and snippets.

@rainux
Created September 11, 2010 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rainux/575409 to your computer and use it in GitHub Desktop.
Save rainux/575409 to your computer and use it in GitHub Desktop.
Simple jQuery().draggable() plugin via http://www.coderholic.com/jquery-draggable-implementation/
(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