Html5 手机网页中,长按会触发系统事件,请问怎么取消这些事件

Html5 手机网页中,长按会触发系统事件,请问怎么取消这些事件,第1张

在页面中样式中加上下面的css代码

*{

-webkit-overflow-scrolling: touch

-webkit-touch-callout:none

-webkit-user-select:none

-khtml-user-select:none

-moz-user-select:none

-ms-user-select:none

user-select:none

}

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8"/>

<title></title>

<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>

</head>

<body>

<div style="width:100%">

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

</div>

<script>

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){

alert("你这是点击,不是长按")

}

return false

}

})

})

function longPress(){

timeOutEvent = 0

alert("长按事件触发发")

}

</script>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7241127.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存