我使用zepto的longtap事件 长按某个图片750ms毫秒后触发某个事件
但是触发事件后,弹出了保存图片。这该怎么办?
window.ontouchstart = function(e) { e.preventDefault(); };
可以试试这样来解决
css
div.img{ position:relative; } div.img:before{ position:absolute; top:0; right:0; bottom:0; left:0; z-index:2; content:"\20"; width:100%; height:100%; display:block; background-color:rgba(255,255,255,0); } div.img>img{ max-width:100%; display:block; }
html
<div class="img"><img src="//static..com/build/global/img/logo-w.svg"></div>
也可以在longTap里判断 event.target.nodeName == 'IMG'
使用img标签微信浏览器会识别,可以用普通div,背景放那张需要长按的图片。
在时间处理函数里加个 event.preventDefault()
阻止浏览器默认的行为。