首页 > Web开发 > 详细

js 延迟执行(转)

时间:2014-12-08 13:44:37      阅读:251      评论:0      收藏:0      [点我收藏+]
<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 延迟执行(转)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!