admin管理员组文章数量:1420166
What is the syntax for mobile touch events in javascript? I tried:
window.document.body.ontouchstart = function() { alert(); }
and
window.document.body.touchstart = function() { alert(); }
It doesn't give any error. And nothing happens on touching the webpage. It seems like addEventListener
is the way to go. But why doesn't window.document.body.ontouchstart
directly work?
What is the syntax for mobile touch events in javascript? I tried:
window.document.body.ontouchstart = function() { alert(); }
and
window.document.body.touchstart = function() { alert(); }
It doesn't give any error. And nothing happens on touching the webpage. It seems like addEventListener
is the way to go. But why doesn't window.document.body.ontouchstart
directly work?
2 Answers
Reset to default 3var theElement = document.getElementById("theElement");
theElement.addEventListener("touchstart", handlerFunction, false);
function handlerFunction(event) {
alert();
}
Try this code:
function foo(event) {
alert();
}
var el = document.getElementsByTagName("canvas")[0];
el.addEventListener("touchstart", foo(), false);
//or
window.document.body.addEventListener("touchstart", foo(), false);
- Event listner documentation
- example jsfiddle here
本文标签: htmlHow to use mobile touch events with pure javascriptStack Overflow
版权声明:本文标题:html - How to use mobile touch events with pure javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745320511a2653356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论