I remember that in a previous essay on "Drag Layer", I implemented dragging by using a Boolean variable to determine whether an element could be dragged.
After reading some things in the past two days, I found that there is no need to set this Boolean variable;
Implementation process:
When the mouse is pressed, give the document object (of course it can also be other DOM objects) Bind a handler function to the movement event, and also bind a release handler function to when the mouse is raised.
//When the mouse is pressed and moved (drag) , the function called;
function startSelection(event){
...
}
//The processing function when canceling the move;
function cancelSelection() {
$ (document).unbind('mousemove', startSelection).unbind('mouseup', cancelSelection);
}
//The function called when the mouse is pressed
function imgMouseDown(event){
$(document).mousemove(startSelection).mouseup(cancelSelection);
}
$img.bind("mousedown",imgMouseDown)
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn