I am considering using the CSS :active
selector to highlight buttons while the user is touching or clicking them. However, by default, its effects in Chrome Mobile seem to be out of sync with the obvious event sources. How do I add Javascript listeners for the changes in :active
state?
(Three bonus questions: Can I get rid of the apparent ~130ms delay between touchstart()
and :active
? Why is this still happening in Chrome 108? I thought the touch delays were solved in 2015?)
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<style>
html, body, pre {
position:absolute; top:0; left:0; right:0; bottom:0;
margin: 0; user-select: none;
}
pre {margin: 10px; overflow-y:auto}
pre:active {
/* my goal is to highlight the content between touchstart and touchend...
but in Chrome it's out of sync */
background-color:#fee;
}
</style>
</head>
<body>
<pre id="ELEM"></pre>
<script>
ELEM = document.getElementById("ELEM")
ELEM.appendChild(document.createTextNode(""));
function Print(s)
{
let t = (new Date() / 1000 % 60).toFixed(2).padStart(5,0);
ELEM.firstChild.nodeValue += `${t}: ${s}\n`;
ELEM.scrollTop = ELEM.scrollHeight;
}
Print("Hello, world!");
EVENTS = ["mouseup", "mousedown", "touchstart", "touchend", "click", "touchcancel", "mouseenter", "mouseout", "focusin"];
for (let e of EVENTS)
document.body.addEventListener(e, () => {Print(e)});
</script>
</body>
</html>