触摸屏和Javascript DOM Mousedown事件 [英] Touch Screen and Javascript DOM Mousedown Event
问题描述
我有一个问题:
addEventListener(mousedown,function(event){
console.log('down fired');
event.target.classList .add('down');
},true);
当使用鼠标时,按住鼠标时立即添加目标元素类,但是当使用触摸屏时,手指被放在元素上时,目标元素类不会改变。
但奇怪的是,控制台日志消息是在下发事件为鼠标点击和ts按下。
有关如何解决这个问题的任何建议?
感谢
编辑
我添加了touchstart事件侦听器,但触发事件不会触发: / p>
addEventListener(touchstart,function(event){
cl('touch fired');
},true);
太晚了,可能有人可以使用它:
event.target
在触摸屏上不起作用,因为您可以使用超过1个手指,所以是更多的目标:
addEventListener(mousedown,function(event){
console.log ');
var t = /touch/.test(event.type)?event.targetTouches [0]:event.target;
t.classList.add('down');
},true);
I have a javascript web application that uses a touchscreen, browser is webkit based.
I am having a problem with this:
addEventListener("mousedown", function(event){
console.log('down fired');
event.target.classList.add('down');
}, true);
When using a mouse, the target element class is added immediately when the mouse is held down, but when using the touchscreen, the target element class is not changed when the finger is held on the element.
The strange thing is however, the console log message is sent on the down event for both the mouse click and the ts press.
Any suggestions on how to solve this ??
Thanks
EDIT
I added the touchstart event listener, but it does not fire on a touch event:
addEventListener("touchstart", function(event){
cl('touch fired');
}, true);
Way too late, but maybe someone else could use it:
event.target
doesn't work on touchscreen, because you could use more than 1 finger, so there are more targets:
addEventListener("mousedown", function(event){
console.log('down fired');
var t = /touch/.test(event.type) ? event.targetTouches[0] : event.target;
t.classList.add('down');
}, true);
这篇关于触摸屏和Javascript DOM Mousedown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!