Skip to content

Instantly share code, notes, and snippets.

@simonwoo
Created August 21, 2014 09:19
Show Gist options
  • Save simonwoo/345d184901322164cfa6 to your computer and use it in GitHub Desktop.
Save simonwoo/345d184901322164cfa6 to your computer and use it in GitHub Desktop.
mousedown,mouseover,mouseup
$('#element').mousedown(function(e) {
// You can record the starting position with
var start_x = e.pageX;
var start_y = e.pageY;
$().mousemove(function(e) {
// And you can get the distance moved by
var offset_x = e.pageX - start_x;
var offset_y = e.pageY - start_y;
return false;
});
$().one('mouseup', function() {
alert("This will show after mousemove and mouse released.");
$().unbind();
});
// Using return false prevents browser's default,
// often unwanted mousemove actions (drag & drop)
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment