Home > Web Front-end > JS Tutorial > body text

jquery mouse stop moving event_jquery

WBOY
Release: 2016-05-16 17:07:58
Original
1263 people have browsed it

复制代码 代码如下:


<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

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