Puppeteer 中文文档v25.8.0

Mouse.wheel() 方法

派发一个 mousewheel 事件。

签名

class Mouse {
  abstract wheel(options?: Readonly<MouseWheelOptions>): Promise<void>;
}

参数

参数

类型

说明

options

Readonly<MouseWheelOptions>

(可选) 可选:MouseWheelOptions

返回值:

Promise<void>

示例

放大某个元素的示例:

await page.goto(
  'https://mdn.mozillademos.org/en-US/docs/Web/API/Element/wheel_event$samples/Scaling_an_element_via_the_wheel?revision=1587366',
);

const elem = await page.$('div');
const boundingBox = await elem.boundingBox();
await page.mouse.move(
  boundingBox.x + boundingBox.width / 2,
  boundingBox.y + boundingBox.height / 2,
);

await page.mouse.wheel({deltaY: -100});