Touch: pageY 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

Touch.pageY 只读属性返回触摸点相对于视口的 Y 坐标,包括任何滚动偏移量。

一个双精度浮点值,表示触摸点相对于视口的 Y 坐标,包括任何滚动偏移量。

示例

此示例演示如何访问 Touch 对象的 Touch.pageXTouch.pageY 属性。Touch.pageX 属性是触摸点相对于视口的水平坐标(以 CSS 像素为单位),包括任何滚动偏移量。Touch.pageY 属性是触摸点相对于视口的垂直坐标(以 CSS 像素为单位),包括任何滚动偏移量。

在下面的简单代码片段中,我们假设用户在 source 元素上发起一个或多个触摸接触,移动触摸点,然后释放所有接触。当 touchmove 事件处理程序被调用时,每个触摸点的 Touch.pageXTouch.pageY 坐标通过事件的 TouchEvent.changedTouches 列表进行访问。

js
// Register a touchmove listeners for the 'source' element
const src = document.getElementById("source");

src.addEventListener("touchmove", (e) => {
  // Iterate through the touch points that have moved and log each
  // of the pageX/Y coordinates. The unit of each coordinate is CSS pixels.
  for (let i = 0; i < e.changedTouches.length; i++) {
    console.log(`touchpoint[${i}].pageX = ${e.changedTouches[i].pageX}`);
    console.log(`touchpoint[${i}].pageY = ${e.changedTouches[i].pageY}`);
  }
});

规范

规范
触摸事件
# dom-touch-pagey

浏览器兼容性