粘贴到html即可看到效果,用于移动端长按删除
<body>
<div class="butlong" style="position:relative;">
<input type="button" value="长按删除" class="delete"/>
<a style="position:absolute; left:90px; top:0; color:red; display:none;" class="deletefont">删除</a>
</div>
</body>
<script src="js/zepto.min.js"></script>
<script type="text/javascript">
// 长按
$.fn.longPress = function(fn) {
var timeout = undefined;
var $this = this;
for(var i = 0;i<$this.length;i++){
$this[i].addEventListener('touchstart', function(event) {
timeout = setTimeout(function(e){
$('.deletefont').show();
}, 800); //长按时间超过800ms,则执行传入的方法
}, false);
$this[i].addEventListener('touchend', function(event) {
clearTimeout(timeout); //长按时间少于800ms,不会执行传入的方法
}, false);
}
}
$('.delete').longPress(function(e){
});
$('.deletefont').on('touchend',function(){
$('.delete').remove();
$('.deletefont').remove();
})
攻城狮博客不定期更新,有错误会及时更正
如有不同见解,请在下方评论。。。
如有错误、后续更正。