3

我有一个基于mousedown事件的工作代码。我想在事件代码开始时将touchstart事件转换为mousedown事件以保留现有代码。

如何正确转换touchstart事件mousedown

touchstart带有事件的示例代码:

var top = event.touches[i].pageY;
4

1 回答 1

2

创建您自己的事件对象,然后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);
于 2012-11-04T12:42:30.363 回答