移动端的点透

移动端的点透
		当上层元素发生点击的时候,下层元素也有点击(焦点)特性,
		在300S之后,如果上层元素消失或隐藏,目标点就会漂移到下层元素身上,
		就会触发点击行为。
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,user-scalable=no"/>
		<title></title>
		<style>
			#div1{
				width: 200px;
				height: 200px;
				background-color: red;
				position: absolute;
				left: 0;
				top:0;
				opacity: 0.5;
			}
		</style>
	</head>
	<body>
		<a href="http://www.miaov.com">点我!!!!</a>
		<div id="div1">1</div>
		<script>
			var div = document.getElementById("div1");
			div.addEventListener('touchend',end);
			function end(){
				this.style.display = 'none';
			}
		</script>
	</body>
</html>

在这里插入图片描述
在这里插入图片描述

解决:
		1.下层不要使用有点击(焦点)特性的元素
<p>点我!!!!</p>
<!--<a href="http://www.miaov.com">点我!!!!</a>-->
       2.阻止pc的事件
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,user-scalable=no"/>
		<title></title>
		<style>
			#div1{
				width: 200px;
				height: 200px;
				background-color: red;
				position: absolute;
				left: 0;
				top:0;
				opacity: 0.5;
			}
		</style>
	</head>
	<body>
		<a href="http://www.miaov.com">点我!!!!</a>
		<div id="div1">1</div>
		<script>
		document.addEventListener('touchstart',function(ev){
			ev.preventDefault();
		});
		
			var div = document.getElementById("div1");
			var a = document.getElementById("a");
			div.addEventListener('touchend',end);
			
			a.addEventListener('touchstart',function(){
				window.location.href = 'http://www.miaov.com';
			})
			
			function end(){
				this.style.display = 'none';
			}
		</script>
	</body>
</html>

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值