[英]How to convert touchstart event to mousedown correctly?
I have a working code based on mousedown
event. 我有一个基于
mousedown
事件的工作代码。 I want to convert touchstart
event to mousedown
event on the beggining of the event's code to preserve existing code. 我想在事件代码开始时将
touchstart
事件转换为mousedown
事件,以保留现有代码。
How to convert touchstart
event to mousedown
correctly? 如何正确将
touchstart
事件转换为mousedown
?
Sample code with touchstart
event: 带有
touchstart
事件的示例代码:
var top = event.touches[i].pageY;
Create your own event object, and then call the function you'd call for a mousedown
event with that event object. 创建您自己的事件对象,然后使用该事件对象调用您要为
mousedown
事件调用的函数。 For example: 例如:
var mousedownEventFunc = function (e){
// use the event object however
alert(e.pageX);
};
document.getElementById('selectorID').addEventListener('touchstart', function (e){
mousedownEventFunc({
pageX: e.touches[0].pageX,
pageY: e.touches[0].pageY
});
}, false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.