Whenever I click on a modal, it changes my body to overflow:hidden
. As a result, the scrollbar disappears and my page becomes unscrollable. Once I close the modal, my body reverts back to overflow:auto
allowing the page to scroll again. These functionalities are implemented using two simple functions that I have defined in my Javascript.
function hideScroll() {
document.querySelector("body").style.overflow = "hidden";
}
function enableScroll() {
document.querySelector("body").style.overflow = "auto";
}
Despite this mechanism being in place, there is a slight 'jank' where the entire page shifts to the right when the scrollbar is removed. Is there a solution to eliminate this effect or perhaps another method to prevent scrolling when the modal is active?