【h5长按事件】H5页面监听长按和点击事件

导读:本篇文章讲解 【h5长按事件】H5页面监听长按和点击事件,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

h5手机端监听长按和点击事件,具体代码如下所示:

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>长按事件测试</title>
		<script src="static/js/jquey1.12.4.js"></script>
		<style type="text/css">

		</style>
	<body>

		<div style="width:100%;">
			<div id="touchArea" style="width:90%; height:200px; background-color:#CCC;font-size:100px">长按我</div>
		</div>

	</body>

	<script>
		// // H5页面监听长按事件

		var timeOutEvent = 0;
		$(function() {
			$("#touchArea").on({
				touchstart: function(e) {
					timeOutEvent = setTimeout("longPress()", 500);
					e.preventDefault();
				},
				touchmove: function() {
					clearTimeout(timeOutEvent);
					timeOutEvent = 0;
				},
				touchend: function() {
					clearTimeout(timeOutEvent);
					if (timeOutEvent != 0) {
						console.log("这是点击,不是长按");
					}
					return false;
				}
			})
		});

		function longPress() {
			timeOutEvent = 0;
			console.log("长按事件触发");
		}
	</script>


</html>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/96010.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!