码迷,mamicode.com
首页 > Web开发 > 详细

js 延迟执行(转)

时间:2014-12-08 13:45:24      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   on   div   art   log   

<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 延迟执行(转)

标签:style   blog   http   io   ar   on   div   art   log   

原文地址:http://www.cnblogs.com/hack0573/p/4150886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!