Last active
May 5, 2022 18:17
-
-
Save KrisKnez/18e25ca0fc112b7e5437d8f62846aa6b to your computer and use it in GitHub Desktop.
Oxygen Builder Disable Scrolling On Modal Open With Pure JS using MutationObserver
This file contains hidden or 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
| function DisableEvent(e) { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| return false; | |
| } | |
| new MutationObserver(function(e) { | |
| let isMobile = window.innerWidth - document.body.offsetWidth < 10; | |
| if (e[0].target.classList.contains("live")) { | |
| if (isMobile) | |
| document.body.style.overflow = "hidden"; | |
| else | |
| document.addEventListener("wheel", DisableEvent, { | |
| passive: false | |
| }); | |
| } else { | |
| document.body.style.removeProperty("overflow"); | |
| document.removeEventListener("wheel", DisableEvent, { | |
| passive: false | |
| }); | |
| } | |
| }).observe(document.querySelector("#%%ELEMENT_ID%%").parentNode, { | |
| attributes: true | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment