admin管理员组文章数量:1401645
Does anyone know why a touchend event would fire during a touchstart event? This only happens the second time around.
A quick code snippet:
function touchstart (event) {
$(event.target).one('touchend', function () {
alert('fired');
}
}
So the first time this is fired it works fine. Second time it fires the alert on touchstart.
/
Edit:
Looks like this could be an iPhone issue only
Does anyone know why a touchend event would fire during a touchstart event? This only happens the second time around.
A quick code snippet:
function touchstart (event) {
$(event.target).one('touchend', function () {
alert('fired');
}
}
So the first time this is fired it works fine. Second time it fires the alert on touchstart.
http://jsfiddle/8SVFR/
Edit:
Looks like this could be an iPhone issue only
Share Improve this question edited Dec 30, 2012 at 16:18 darylhedley asked Dec 30, 2012 at 15:35 darylhedleydarylhedley 2581 gold badge8 silver badges23 bronze badges 7- Are we talking about mobile phone browser? Works just fine on my Android 4.1 native browser. – try-catch-finally Commented Dec 30, 2012 at 15:55
- Works fine too in Chrome and Firefox (mobile) on Android 4.1 too. – try-catch-finally Commented Dec 30, 2012 at 15:56
- Only tried it on iPhone and it fires on touchstart the second time around – darylhedley Commented Dec 30, 2012 at 15:58
-
I've noticed, depending on the Android version and device sometimes a touch does not get exactly recognized, escpeciall on small buttons. Maybe this is the case? Here's an improved fiddle with a bigger button and logging to the documents body using
html()
: jsfiddle/tuGZx/1 – try-catch-finally Commented Dec 30, 2012 at 15:58 - Ok what's weird is if you put in an alert into this updated jsfiddle it fires again on the second touchstart. To get this to work you need to hold the button for a bit. Maybe it's just the alert firing it again? – darylhedley Commented Dec 30, 2012 at 16:03
2 Answers
Reset to default 5Turns out...by having an alert fire in a touchend event causes all sorts of problems. When you click 'ok' it fires the touchstart so the touchend gets fired next time you touch the element. Luckily I was using the alert to check my code - so once this was removed my code worked perfectly!
Just put code of "touchend" handler in setTimeout with 0ms. Like this:
$(someElement).on("touchend",
function(){
setTimeout(function(){
/*Your code*/
}, 0);
});
本文标签: javascriptTouchend fires on touchstart second time aroundStack Overflow
版权声明:本文标题:javascript - Touchend fires on touchstart second time around - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744301444a2599603.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论