如何正确将接触点事件转换为Mousedown



我有一个基于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);

最新更新