Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

disable scroll on modal open

// Select required elements from the DOM
const modal = document.querySelector("#modal");
const body = document.querySelector("body");

const showModal = function (e) {
modal.classList.toggle("hidden");

if (!modal.classList.contains("hidden")) {
// Disable scroll
body.style.overflow = "hidden";
} else {
// Enable scroll
body.style.overflow = "auto";
}
};
Comment

prevent page scrolling when a modal is open

// When the modal is shown, we want a fixed body
document.body.style.position = 'fixed';
document.body.style.top = `-${window.scrollY}px`;

// When the modal is hidden...
const scrollY = document.body.style.top;
document.body.style.position = '';
document.body.style.top = '';
window.scrollTo(0, parseInt(scrollY || '0') * -1);
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongodb update many 
Javascript :: javascript pass object by value 
Javascript :: vue event focus out 
Javascript :: get date js 
Javascript :: jquery if .val is blank 
Javascript :: How to write inside a div using javascript 
Javascript :: How to call a c# functio from Javascript 
Javascript :: vue js countdown timer 
Javascript :: palindrome rearranging javascript 
Javascript :: uncheck a checkbox in javascript 
Javascript :: create react portal 
Javascript :: javascript format date object to yyyy-mm-dd 
Javascript :: regex for non empty string 
Javascript :: prepend to array javascript 
Javascript :: javascript extract number from string 
Javascript :: convert file to blob in angular 
Javascript :: While loop factorial function in javascript 
Javascript :: what called window.onerror 
Javascript :: jquery $(document.on click 
Javascript :: javascript check if string contains character 
Javascript :: jest writing test 
Javascript :: js string does not contain 
Javascript :: unshift 
Javascript :: moment cdn 
Javascript :: if datatable is null js 
Javascript :: how to add oAuth google signin in react native app 
Javascript :: js convert to fraction 
Javascript :: mmap() failed: [12] Cannot allocate memory composer 
Javascript :: javascript websocket 
Javascript :: multiple records in json 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =