解决 ios手机访问H5页面而 $(document).on绑定无效问题

<!DOCTYPE html>
<html>
<head>
	<meta charset='utf-8'>
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
	<title></title>
	<style type="text/css">
		.grid{
			background-image:-webkit-linear-gradient(top,
							transparent 49px,
							#bfbebe 50px),
							-webkit-linear-gradient(left,
							transparent 49px,
							#bfbebe 50px);

			background-size:50px 50px;
			background-repeat:repeat;                     /*先画个网格,便于布局*/
		}

		/*主容器*/
		.main-container{
			position:absolute;
			left:0;
			top:0;
			width:100%;
			height:1000px;
		}

		/*BOX*/
		.box{
			width:100px;
			height:50px;
			background-color:grey;
			margin:100px;
			position:relative;
			color:white;
			text-align:center;
			line-height:50px;
                        /* 解决IOS不触发事件问题 **/
			cursor: pointer;
		}

		.box-style{
		/*	margin-top:10px;
			transition-property:margin-top;
			transition-duration:2s;
			transition-timing-function: ease-out;
			transition-delay:0;*/
			width:200px;
			height:100px;
			transition:width 1s ease-in-out,height 4s 1s ease-out;
		}
		/**/
			position:relative;
			width:100px;
			height:50px;
			border:1px solid black;
			/*-webkit-animation:demo 10s;*/
			-webkit-animation-name:demo;
			-webkit-animation-duration:2s;
			-webkit-animation-timing-function:ease-in;
			-webkit-animation-delay:0s;
			-webkit-animation-iteration-count:1;
			-webkit-animation-direction:alternate;
			-webkit-animation-fill-mode:backwards;
		}

		@-webkit-keyframes demo{
			0% {left:0;background-color:white;}
			50% {left:200px;background-color:yellow;}
			100% {left:0px;background-color:red;}
		}
		div{
			box-sizing:border-box;
		}
		.dialogue-mask{
			position:absolute;                        /*弹出层*/
			left:0;
			top:0;
			width:100%;
			height:100%;
			background-color:rgba(128,128,128,0.5);
			display:none;
			overflow:auto;
		}
		.dialogue-container{
			position:absolute;
			width:80%;
			left:50%;
			top:40%;
			box-sizing:border-box;
			-webkit-transform:translate(-50%,-50%);
			background-color:white;
			box-shadow: 1px 1px 1px 1px #cdcfda;
		    border-radius: 10px;
		    padding:15px;
		    display:block;
		    z-index:2;
		}

		.dialogue-title{
			font-size:16px;
			font-weight:bold;
			line-height:30px;
			position:relative;
		}

		.border-bottom::after{
			content:"";
			width:100%;
			height:1px;
			position:absolute;
			bottom:0;
			left:0;
			background-color:#b9b9b9;
			-webkit-transform:scaleY(0.5);

		}

		.dialogue-content{
			font-size:14px;
			line-height:25px;
			position:relative;
		}

		.dialogue-btn{
			margin-top:10px;
			text-align: center;
		}

		.clear-float::after{
			content:"";
			display:block;
			clear:both;
		}

		.dialogue-cancel{
			float:right;
			margin-right:20px;
			padding: 8px 25px;
			color:grey;
			background-color:white;
			border-radius:3px;
			border:1px solid #e2e1e1;
		}

		.dialogue-sure{
			float:right;
			padding: 8px 25px;
			color:white;
			background-color:#229ffd;
			border-radius:3px;
		}


		@-webkit-keyframes dialogue-in{
			0% {top:0;}
			50% {top:40%;}
			90% {top:37%;}
			100% {top:40%;}
		}

		.animation-dialogue-in{
			display:block;

			-webkit-animation:dialogue-in 0.5s cubic-bezier(0.215, 0.610, 0.355, 1.000);
		}


		/*隐藏滚动条*/
		.forbid-scroll{
			height:100%;
			overflow:hidden;
		}
	</style>
	<script type="text/javascript" src = "/common/js/station/c.jquery1.8.3.min.js" ></script>
	<script type="text/javascript">
		$(document).on("click",".box",function(){
			$(".dialogue-mask").show();
			$(".dialogue-container").addClass("animation-dialogue-in");
			$("body,html").addClass("forbid-scroll");//弹出层后,禁用body和html滚动
		});
		$(document).on("click",".dialogue-cancel",function(){
			$(".dialogue-mask").hide();
			$(".dialogue-container").removeClass("animation-dialogue-in");
			$("body,html").removeClass("forbid-scroll");
		});
		$(document).on("click",".dialogue-sure",function(){
			console.log("You have clicked the sure button")
		});
	</script>
</head>
<body>
	<div class="main-container grid">
		<div class="box">
			弹出对话框
		</div>
	</div>
	<div class="dialogue-mask">
		<div class="dialogue-container">
			<div class="dialogue-title border-bottom">
				对话框标题
			</div>
			<div class="dialogue-content border-bottom">
				这里是对话框内容,比如:你确定要提交调查信息吗?
			</div>
			<div class="dialogue-btn clear-float">
				<div class="dialogue-sure">
					确认
				</div>
				<div class="dialogue-cancel">
					取消
				</div>
			</div>
		</div>
	</div>
</body>
</html>


以上为一个POP弹窗带码,目标是在手机上访问。


经测试 IOS 没有触发$(document).on("clike",".box",function());事件,而android系统上就没有问题,在网上查到一个很巧妙的方式,就是给需要绑定事件的元素添加一个css cursor: pointer

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值