Skip to content

Instantly share code, notes, and snippets.

@max-verem
Forked from cbeard87/trigger-wheel-event.js
Created June 20, 2022 10:52
Show Gist options
  • Save max-verem/78bd2c067a6a5c661d0ef441fb135773 to your computer and use it in GitHub Desktop.
Save max-verem/78bd2c067a6a5c661d0ef441fb135773 to your computer and use it in GitHub Desktop.
Dispatch a mouse wheel event
const wheelEvt = document.createEvent('MouseEvents');
wheelEvt.initEvent('wheel', true, true);
// Set deltaY depending on wheel up or wheel down
wheelEvt.deltaY = +120;
// wheelEvt.deltaY = -120;
// Pass event to element
element.dispatchEvent(wheelEvt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment