Touch:screenX 属性
返回触摸点相对于屏幕的 X 坐标,不包括任何滚动偏移。
值
一个数字。
示例
此示例说明如何访问 Touch 对象的 Touch.screenX 和 Touch.screenY 属性。Touch.screenX 属性是触摸点相对于屏幕的水平 (x) 坐标(以 CSS 像素为单位)。Touch.screenY 属性是触摸点相对于屏幕的垂直坐标(以 CSS 像素为单位)。
在下面的简单代码片段中,我们假设用户在 ID 为 source 的元素上发起多次触摸接触,然后释放接触。当 touchstart 事件处理程序被调用时,会访问每个触摸点的 Touch.screenX 和 Touch.screenY 坐标。
js
// Register a touchstart listeners for the 'source' element
const src = document.getElementById("source");
src.addEventListener("touchstart", (e) => {
// Iterate through the touch points and log each screenX/Y coordinate.
// The unit of each coordinate is CSS pixels.
for (let i = 0; i < e.touches.length; i++) {
console.log(`touchpoint[${i}].screenX = ${e.touches[i].screenX}`);
console.log(`touchpoint[${i}].screenY = ${e.touches[i].screenY}`);
}
});
规范
| 规范 |
|---|
| 触摸事件 # dom-touch-screenx |
浏览器兼容性
加载中…