Last active
November 29, 2020 00:32
-
-
Save jongacnik/8676514636d450d7acef3b65132c4de0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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