Home >Web Front-end >JS Tutorial >jquery mouse stop moving event_jquery

jquery mouse stop moving event_jquery

WBOY
WBOYOriginal
2016-05-16 17:07:581325browse

复制代码 代码如下:


<script><br>(function($){<br> $.fn.moveStopEvent = function(callback){<br>  return this.each(function() {<br>   var x = 0,<br>    y = 0,<br>    x1 = 0,<br>    y1 = 0,<br>    isRun = false,<br>    si,<br>    self = this; <p>   var sif = function(){<br>    si = setInterval(function(){<br>         if(x == x1 && y ==y1){<br>          clearInterval(si);<br>          isRun = false;<br>          callback && callback.call(self);<br>         }<br>         x = x1;<br>         y = y1;<br>        }, 500);<br>   }</p> <p>   $(this).mousemove(function(e){<br>    x1 = e.pageX;<br>    y1 = e.pageY;<br>    !isRun && sif(), isRun = true;<br>   }).mouseout(function(){<br>    clearInterval(si);<br>    isRun = false;<br>   });<br> });<br> }<br>})(jQuery);</p> <p>$(function(){<br> $("#div1,#div2").moveStopEvent(function(){<br>   alert($(this).attr("id"));<br>  }<br> );<br>});<br></script>
div1



div2

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