我将html5画布设置为适合我的屏幕宽度,像这样:
canvas.width = screenWidth;
canvas.height = screenHeight;
但是当我这样做的时候:
canvas.addEventListener("touchstart", function(e) {
var x = e.touches[0].screenX;
var y = e.touches[0].screenY;
console.log(x.toString() + "X");
});
x和y总是非常小,为什么会这样,我该如何修复它?
编辑:我希望我的触摸事件是准确的,因为我正在制作一款依赖于它们的游戏
您正在获取哪些值?
你的index。html里有吗?
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
与电脑不同,移动设备上的浏览器以不同于1的像素密度运行。
例如,如果像素密度为2,则期望看到的值减小2倍。
尝试在您的桌面Chrome上运行它,激活仿真(开发人员工具->仿真)。
选择与测试相同的设备,并比较这些值。