user-scalable=no
(禁止縮放)width
或者initial-scale
touch-action: manipulation;
.For IE10 use -ms-touch-action: manipulation;
發生狀況:html
touchstart/touchend
事件,使上層的A點擊後消失爲何會產生點透:瀏覽器
touchstart -> touchend -> click
解決方案:app
touchstart/touchend
事件,調用event.preventDefault
或者event.returnValue = false
click
事件作綁定<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <!-- wipe 300ms delay --> <!-- Instead of above code, your can see div2 has 300ms delay --> <meta name="viewport" content="user-scalable=no, initial-scale=1.0"> <style> *{ margin: 0px; padding:0px; } #div1{ width: 300px; height: 300px; background-color: rgba(255,0,0,0.25); } #div2{ width: 240px; height: 240px; background-color: yellow; position: absolute; left: 30px; top: 30px; z-index: -1; } #console{ border: 1px solid green; position: absolute; top: 300px; width: 100%; } </style> </head> <body> <div id="div1"></div> <div id="div2"> <a href="http://www.baidu.com">jump to baidu.com</a> </div> <div id="console"></div> <script> $ = function (id) {return document.getElementById(id)} var div1 = $("div1"); var div2 = $('div2'); var con = $('console'); var sDate, eDate; function handle(e){ // computed time interval if (sDate == null) { sDate = (new Date).getTime() } eDate = (new Date).getTime() var tar = e.target, eve = e.type; // prevent 點透 if(eve == "touchend") { console.log(tar) e.preventDefault(); } var ele = document.createElement("p"); ele.innerHTML = "target:"+ tar.id + " event:" + eve + ' interval: ' + (eDate-sDate) + 's'; con.appendChild(ele); if(tar.id === "div1"){ div1.style.display = "none"; } } div1.addEventListener("touchend",handle); div1.addEventListener("touchstart",handle); div2.addEventListener("click",handle); </script> </body> </html>