[英]Javascript timeout or mouseup event, but not both in Android browsers?
I'm trying to write a javascript web-app where an action is taken on mouseup
, and another action is taken after the user has held down the button long enough. 我正在尝试编写一个javascript网络应用程序,其中对
mouseup
操作,然后在用户按住按钮足够长的时间后执行另一操作。 My code works in every browser I have tried on Windows and Linux, but on all three Android browsers I've tried (Chrome, Firefox, and native) I seem to lose the mouseup
event if the timer fires. 我的代码可在我在Windows和Linux上尝试过的所有浏览器中运行,但是在我尝试过的所有三个Android浏览器(Chrome,Firefox和本机)上,如果计时器触发,我似乎会丢失
mouseup
事件。
The core of my code seems quite straightforward: 我的代码的核心似乎很简单:
btn.addEventListener("mousedown", function(){
myTimer = setTimeout(function(){
btn.textContent += "t";
outVal = "b";
}, 500);
});
btn.addEventListener("mouseup", function(){
clearTimeout(myTimer);
btn.textContent += outVal;
outVal = "a"
});
Jsfiddle here: https://jsfiddle.net/wanderinglogic/sycL0e53/ 此处的jsfiddle: https ://jsfiddle.net/wanderinglogic/sycL0e53/
On non-Android browsers, if the user releases the button after a short time it outputs a
, if the user holds the button it (after 500ms) outputs t
and then when the user releases the button outputs b
. 在非Android浏览器上,如果用户在短时间后释放按钮,则输出
a
;如果用户按住按钮,则它(在500ms之后)输出t
;然后,当用户释放按钮时,输出b
。
But on Android browsers, if the users releases the button after a short time it still outputs a
, and if the user holds the button it (after 500ms) still outputs t
, but then the final button release doesn't output b
. 但是在Android浏览器上,如果用户在短时间内释放按钮,它仍然会输出
a
;如果用户按住按钮,它(500毫秒后)仍然会输出t
,但最终的按钮释放不会输出b
。
Is there some extra event on Android that is interfering with my mouseup
that I don't know about? Android上是否有一些额外的事件会干扰我不知道的
mouseup
?
Well, Android does (in general) does not have mouse input... On touch would be better way to describe it. 好吧,Android(通常)没有鼠标输入...触摸将是描述它的更好方法。 And as such the user input works differently then on non-touch interfaces.
因此,用户输入的工作方式与非触摸界面上的工作方式不同。 This whole touchy subject was the death for mouse over events.
整个敏感主题是鼠标悬停事件的死亡。 See: understanding touch events
另请: 了解触摸事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.