首页 > 代码库 > js 延迟执行(转)
js 延迟执行(转)
<div id="aaa" style="height:200px; width:200px; background:#CCC;"></div><div id="bbb" style="height:200px; width:200px; background:#CFC;"></div><script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-1.8.2.min.js"></script><script>$.fn.hoverDelay = function(options){ var defaults = { hoverDuring: 2000, outDuring: 2000, hoverEvent: $.noop, outEvent: $.noop }; var sets = $.extend(defaults, options || {}); return $(this).live("hover",function(event) { var that = this; if(event.type =="mouseenter"){ clearTimeout(that.outTimer); that.hoverTimer = setTimeout( function(){sets.hoverEvent.apply(that)}, sets.hoverDuring ); } else { clearTimeout(that.hoverTimer); that.outTimer = setTimeout( function(){sets.outEvent.apply(that)}, sets.outDuring ); } });}$("#aaa").hoverDelay({ hoverEvent: function(){ $("#bbb").html("进入"); }, outEvent:function(){ $("#bbb").html("离开"); }});</script>
js 延迟执行(转)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。