<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>长按</title>
<style>
body {
-webkit-touch-callout: none !important;
-webkit-overflow-scrolling: touch;
}
img,a{
pointer-events: none;
}
.long{
-webkit-user-select: none;
}
</style>
<script src="jquery-3.0.0.min.js"></script> //当然也可以引入绝对路径
<body>
<div style="margin-left: 200px;margin-top: 100px"><button class="long" style="width:100px;height:100px; user-select: none;"></button></div>
<div style="margin-top: 100px;margin-left: 100px"><span id="num" style="font-size: 100px;">5</span></div>
<script>
window.document.oncontextmenu = function (e) {
e.preventDefault();
};
var $long = $('.long');
var timer = null;
$long.on('touchstart', function(){
plus('#num');
});
$long.on('touchend', function(){
clearTimeout(timer);
});
function plus(ele){
var num = parseInt($(ele).text());
$(ele).text(++num);
timer = setTimeout(function(){
plus(ele);
}, 200);
}
</script>
</body>
</html>
网友评论