Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Last active November 29, 2020 00:32
Show Gist options
  • Save jongacnik/8676514636d450d7acef3b65132c4de0 to your computer and use it in GitHub Desktop.
Save jongacnik/8676514636d450d7acef3b65132c4de0 to your computer and use it in GitHub Desktop.
import { define } from 'wicked-elements'
define('[data-component~="overscroll-none"]', {
init () {
},
connected () {
if (!CSS.supports('overscroll-behavior', 'none')) {
this.wheelingTimeout = false
this.lock = this.lock.bind(this)
this.unlock = this.unlock.bind(this)
this.lockOnce = this.lockOnce.bind(this)
this.element.addEventListener('wheel', this.lockOnce)
this.element.addEventListener('mouseenter', this.lock)
this.element.addEventListener('mouseleave', this.unlock)
}
},
disconnected () {
if (!CSS.supports('overscroll-behavior', 'none')) {
this.element.removeEventListener('wheel', this.lockOnce)
this.element.removeEventListener('mouseenter', this.lock)
this.element.removeEventListener('mouseleave', this.unlock)
}
},
lockOnce () {
document.documentElement.style.overflow = 'hidden'
this.element.removeEventListener('wheel', this.lockOnce)
},
lock () {
document.documentElement.style.overflow = 'hidden'
},
unlock () {
document.documentElement.style.overflow = 'auto'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment