Jquery mouse stop move event
This article mainly introduces the jquery mouse stop movement event. If you need it, refer to it.
The Code is as follows:
<Script src = "jquery. js"> </script>
<Script>
(Function ($ ){
$. Fn. moveStopEvent = function (callback ){
Return this. each (function (){
Var x = 0,
Y = 0,
X1 = 0,
Y1 = 0,
IsRun = false,
Si,
Self = this;
Var sif = function (){
Si = setInterval (function (){
If (x = x1 & y = y1 ){
ClearInterval (si );
IsRun = false;
Callback & callback. call (self );
}
X = x1;
Y = y1;
},500 );
}
$ (This). mousemove (function (e ){
X1 = e. pageX;
Y1 = e. pageY;
! IsRun & sif (), isRun = true;
}). Mouseout (function (){
ClearInterval (si );
IsRun = false;
});
});
}
}) (JQuery );
$ (Function (){
$ ("# Div1, # div2"). moveStopEvent (function (){
Alert ($ (this). attr ("id "));
}
);
});
</Script>
<Div id = "div1" style = "width: 200px; height: 100px; background-color: # ccc;"> div1 </div>
<Br/>
<Div id = "div2" style = "width: 200px; height: 100px; background-color: # ccc;"> div2 </div>