[英]ontouchstart acting weird on mobile devices?
I am working on a game and i am using ontouchstart as a way to handle au ser tapping on the screen.我正在开发一款游戏,我正在使用 ontouchstart 作为处理屏幕上的用户点击的一种方式。 but when i click on the screen it does not register the first time, it makes me click it twice for it to register even one click.
但是当我点击屏幕时,它第一次没有注册,它让我点击了两次,它甚至可以注册一次。 I have no idea what to do.
我不知道该怎么做。 does anyone know a fix?
有人知道修复吗?
I decided to update my code with a more simplified version of it.我决定用更简化的版本更新我的代码。 this is not working either.
这也不起作用。 on an IOS device at least, no matter what browser i use, i have to tap twice for it to register once.
至少在 IOS 设备上,无论我使用什么浏览器,我都必须点击两次才能注册一次。
<html>
<link href="https://fonts.googleapis.com/css?family=Press+Start+2P&display=swap" rel="stylesheet" />
<body>
<h1 class="center-align" id="cn">click me</h1>
<h2 id="cl">clicked:</h2>
</body>
<script>
let click = 1;
document.getElementById("cn").ontouchstart = () => {
click++;
document.getElementById("cl").innerHTML = "clicked: " + click;
};
</script>
</html>
Hey can you try removing the touch-action
from the styles?嘿,您可以尝试从 styles 中删除
touch-action
吗? Manipulating touch action ends up affecting touch event listeners操纵触摸动作最终会影响触摸事件侦听器
EDIT编辑
Can you try this instead?你可以试试这个吗?
object.addEventListener("touchstart", myScript);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.