您的位置
主页 > 网站技术 > 语言编程 > » 正文

jquery鼠标停止移动事件

来源: 站长圈 点击:

本文主要介绍了jquery鼠标停止移动事件,有需要的朋友可以参考一下,希望对大家有所帮助!

复制代码 代码如下:

<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(){

 $("#p1,#p2").moveStopEvent(function(){

   alert($(this).attr("id"));

  }

 );

});

</script>

<p id="p1" style="width:200px;height:100px;background-color:#ccc;">p1</p>

<br/>

<p id="p2" style="width:200px;height:100px;background-color:#ccc;">p2</p>




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明