Skip to content

Instantly share code, notes, and snippets.

@FelixLuciano
Last active April 10, 2023 11:13
Show Gist options
  • Save FelixLuciano/aee75b72d655f72b8d729615861d0147 to your computer and use it in GitHub Desktop.
Save FelixLuciano/aee75b72d655f72b8d729615861d0147 to your computer and use it in GitHub Desktop.
Horizontal scrolling
const target = document.querySelector('div')
target.addEventListener('wheel', event => {
const toLeft = event.deltaY < 0 && target.scrollLeft > 0
const toRight = event.deltaY > 0 && target.scrollLeft < target.scrollWidth - target.clientWidth
if (toLeft || toRight) {
event.preventDefault()
event.stopPropagation()
target.scrollLeft += event.deltaY
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment