我有一个基于mousedown
事件的工作代码。我想将touchstart
事件转换为mousedown
事件,以启动事件代码以保留现有代码。
如何正确将touchstart
事件转换为mousedown
?
带有touchstart
事件的示例代码:
var top = event.touches[i].pageY;
创建自己的事件对象,然后调用带有该事件对象的mousedown
事件的函数。例如:
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);