jquery clone 与 clone(true) 的区别

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Flappy bird</title>
	<script src="jquery-1.8.0.js"></script>
	<style type="text/css">
		#xc{
			width:300px;
			height:600px;
			margin:0 auto;
			background-color:#FFFFFF;
			position:absolute;
			left:230px;
			z-index:10;
		}
		#cj{
			width:300px;
			height:500px;
			margin:0 auto;
			background-color:#00CCCC;
			border:double;
		}
		#bird{
			background:url(bird.png);
			width:50px;
			height:50px;
			margin-top:200px;
			display:inline-block;
			float:left;
			margin-left:50px;
			
		}
		.obs{
			background-color:#333333;	
			width:50px;
			height:500px;
			position:absolute;
			left:750px;
			
		}
		.ob{
			background:url(pipe.png);
			width:50px;
			height:50px;
		}
	</style>
</head>

<body>
	<div id="xc"></div>
	<div id="cj">
		<div id="bird">
		
		</div>
		<div class="obs">
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
			<div class="ob"></div>
		</div>
	</div>
	<script type="text/javascript">
		function getRandom(n){
			return Math.floor(Math.random()*n+1)
		}
		function checkAnimate(e){
			if(e.which  == 13){
				$(".obs").animate({left:'-=300'},3000);
			}
		}
		var obs= $(".ob");
		var r1 = getRandom(7);
		obs.eq(r1).css("visibility","hidden");
		obs.eq(r1+1).css("visibility","hidden");
		
		$("body").keydown(function(e){
			checkAnimate(e);
			if(obs.offset().left == 450){
				var cl = $(".obs").clone(false);
				$("body").append(cl.css("left","750px").css('top',"10px"));
				cl.animate({left:'-=300'},3000);
			}
		
		})
	</script>
</body>
</html>

今天写Flappy bird的时候发现的 

 clone , clone(true)的区别在于,clone(ture)除了克隆集合,还会克隆click句柄 即会克隆事件,触发被克隆对象的监听器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值