Home > Web Front-end > JS Tutorial > Mouse drag effect code based on jquery_jquery

Mouse drag effect code based on jquery_jquery

WBOY
Release: 2016-05-16 17:53:03
Original
1038 people have browsed it

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.

Copy code The code is as follows:

//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)
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template