扫码关注官方订阅号
现在有个需求。。是模拟微信语音交互的可是长按有个菜单,是显示的“在浏览器中打开”请问这个能屏蔽掉吗?
ringa_lee
这个靠CSS好像没法解决. 用JS吧. 以下是一个案例:
<a href="#"></a> <a href="#" id="pointer"></a> <style> a { display: block; width: 200px; height: 200px; background: #000; } a:last-of-type { background: #ff0000; } </style> <script> var t; var pointer = document.querySelector('#pointer'); var cancelTimeout = function() { if(t) { clearTimeout(t); t = null; } }; pointer.addEventListener('touchstart', function(e) { t = setTimeout(function() { alert('2s!'); cancelTimeout(); }, 2000); e.preventDefault(); return false; }); pointer.addEventListener('touchend', cancelTimeout); pointer.addEventListener('touchcancel', cancelTimeout); </script>
touchstart事件发生的时候阻止默认事件, 由于是长按判断, 就加个定时器.
touchstart
试试
-webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
试试这个
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
这个靠CSS好像没法解决. 用JS吧. 以下是一个案例:
touchstart事件发生的时候阻止默认事件, 由于是长按判断, 就加个定时器.试试
试试这个