Created
August 21, 2014 09:19
-
-
Save simonwoo/345d184901322164cfa6 to your computer and use it in GitHub Desktop.
mousedown,mouseover,mouseup
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
$('#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