Skip to content

Instantly share code, notes, and snippets.

@KrisKnez
Last active May 5, 2022 18:17
Show Gist options
  • Select an option

  • Save KrisKnez/18e25ca0fc112b7e5437d8f62846aa6b to your computer and use it in GitHub Desktop.

Select an option

Save KrisKnez/18e25ca0fc112b7e5437d8f62846aa6b to your computer and use it in GitHub Desktop.
Oxygen Builder Disable Scrolling On Modal Open With Pure JS using MutationObserver
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