Skip to content

Instantly share code, notes, and snippets.

@cbeard87
Created July 14, 2019 03:24
Show Gist options
  • Save cbeard87/524c76165f4ed50184dd8787994c7651 to your computer and use it in GitHub Desktop.
Save cbeard87/524c76165f4ed50184dd8787994c7651 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