问题
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