Created
September 27, 2012 23:46
-
-
Save asolove/3797131 to your computer and use it in GitHub Desktop.
Naive drag and drop
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
var draggable = $("#drag"); | |
var handle = draggable.find(".handle"); | |
handle.on("mousedown.drag", function mousedown(e){ | |
handle.off("mousedown.drag"); | |
draggable.animate({ opacity: 0.5 }); | |
draggable.on("mouseup.drag", function mouseup(e){ | |
draggable.off("mouseup.drag"); | |
$("body").off("mousemove.drag"); | |
handle.on("mousedown", mousedown); | |
draggable.animate({ opacity: 1 }); | |
// detect location and possibly do something | |
}); | |
$("body").on("mousemove.drag", _.throttle(function(e){ | |
draggable.css({ left: e.pageX, top: e.pageY }); | |
}, 100)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment