e.changedTouches[0].pageX - uncaught TypeError: Cannot read property '0' of undefined

非 Y 不嫁゛ 提交于 2021-02-10 18:50:16

问题


Well, i need to get the touch position in hand devices. For that i have use below code

var touchX = e.changedTouches[0].pageX;

on tap I'm getting the position of it as expected. But in the console there is a error thrown as below:

Uncaught TypeError: Cannot read property '0' of undefined at HTMLDocument.mouseover (index1.html:152)

Can someone help me on this.


回答1:


found the answer. We need to use device specific conditions for touch events and mouse event.

var docWidth = window.innerWidth;
if(docWidth <= 1024){
                var touchX = e.changedTouches[0].pageX;
                var touchY = e.changedTouches[0].pageY;
                mouseout(e)
            }
            else{
                var mouseX = e.clientX;
                var mouseY = e.clientY;
            }


来源:https://stackoverflow.com/questions/49230576/e-changedtouches0-pagex-uncaught-typeerror-cannot-read-property-0-of-unde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!