我已在Chrome开发人员工具中启用了“仿真触摸事件”选项。我建立了一个简单的测试程序,当我触摸<div>
时发出警报。该程序在我的Galaxy Nexus上运行良好,但是当我在Chrome中单击<div>
时,即使启用了“仿真触摸事件”选项,也没有任何反应。有什么建议么?我是否正确使用此工具?Chrome“仿真触摸事件”不起作用
这是我的代码 - 没什么太花哨。
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
#main_div
{
position: absolute;
width: 50px;
height: 20px;
background-color: red;
top: 50%;
left: 20px;
}
</style>
<script type="text/javascript">
function init()
{
main_div = document.getElementById("main_div");
main_div.ontouchstart = function()
{
alert("here");
}
}
</script>
</head>
<body onload="init()">
<div>
<p id="x">hello</p>
<p id="y"></p>
</div>
<div id="main_div">
hello
</div>
</body>
</html>
我运行的版本是19.0.1084.56。 –
您偶然会将页面放大/缩小吗?据了解,Chrome浏览器中的事件坐标(包括鼠标以及触摸的坐标)都取决于缩放和页面布局。因此,你可能只是垂直“丢失”目标div。 –
我检查了我的缩放级别 - 我在标准缩放。我也疯狂地点击了我的目标,希望Chrome浏览器正确读取我的坐标,但唉,无济于事。感谢您的建议。 –