Skip to main content

Touchscreen

触摸屏类在相对于视口左上角的主框架 CSS 像素中运行。触摸屏上的方法只能在已初始化并将 hasTouch 设置为 true 的浏览器上下文中使用。

🌐 The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the touchscreen can only be used in browser contexts that have been initialized with hasTouch set to true.

此类仅限于模拟轻触手势。有关通过手动分发触摸事件来模拟其他手势的示例,请参见 模拟旧版触摸事件 页面。

🌐 This class is limited to emulating tap gestures. For examples of other gestures simulated by manually dispatching touch events, see the emulating legacy touch events page.


方法

🌐 Methods

tap

Added before v1.9 touchscreen.tap

在位置 (x, y) 使用单次触摸分派 touchstarttouchend 事件。

🌐 Dispatches a touchstart and touchend event with a single touch at the position (x,y).

note

Page.tap() 方法将在浏览器上下文的 setHasTouch 选项为 false 时抛出异常。:::

用法

Touchscreen.tap(x, y);

参数

  • x double#

    相对于主框架视口的 X 坐标(以 CSS 像素为单位)。

  • y double#

    相对于主框架视口的 Y 坐标(以 CSS 像素为单位)。

返回