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 body from scrolling when a modal is opened

$('#adminModal').modal().on('shown', function(){
    $('body').css('overflow', 'hidden');
}).on('hidden', function(){
    $('body').css('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 :: nextjs apollo 
Javascript :: generate a link with javascript 
Javascript :: loop backwards javascript 
Javascript :: upload image with react 
Javascript :: path js 
Javascript :: template literal 
Javascript :: Pause the stream returned by getUserMedia 
Javascript :: url enocde in javascript 
Javascript :: user authentication and routing + nodejs + express 
Javascript :: how to save data in javascript 
Javascript :: react native app exit 
Javascript :: JavaScript Rules for Naming JavaScript Variables 
Javascript :: react props class based static proptypes 
Javascript :: navlink react active class 
Javascript :: javascript Skip Items 
Javascript :: javascript variable name arguments and eval are not allowed 
Javascript :: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. 
Javascript :: jquery callback functions 
Javascript :: javascript process.env.key with  
Javascript :: javascript template string condtioning 
Javascript :: Disemvowel Trolls 
Javascript :: phaser create animation on sprite 
Javascript :: complex expression in programming 
Javascript :: show data time &refresh 
Javascript :: javascript concat two htmlcollection 
Javascript :: Set A Function For An Element 
Javascript :: js convert string to number 
Javascript :: mongoose schema example 
Javascript :: extract data from pdf nodejs 
Javascript :: js string 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =