What I want to do is, when the modal is open, disable JavaScript scrolling for the entire page. The problem is that when I open the modal and try to scroll, it does move the content behind the modal, which is the actual web page, and I want to disable that. When the modal is opened, the background should be frozen.
The code you provided seems correct to disable scrolling when the modal is opened. However, there are several possible causes of the problem:
openModalfunction you defined in the script. Instead, it directly manipulates the modal's style. This means that theisModalOpenvariable is not set totrueand thedisableFullPageScrollfunction is not called. To solve this problem you should use theopenModalfunction when the button is clicked:closeModalfunction. It should look like this:×closeModalThe function is not defined in the global scope, but it is called from HTML. This may cause errors. To solve this problem, you should define thecloseModalfunction in the global scope:The
Please try these suggestions and let me know if they solve your problem.disableFullPageScrollandenableFullPageScrollfunctions use FullPage.js methods to disable and enable scrolling. If you are not using FullPage.js, or it is not initialized correctly, these methods will not work. You should check that FullPage.js is included and initialized correctly in your project.The
overflowpreventDefaultandstopPropagationmethods in a scroll event handler may not be sufficient to prevent scrolling in all cases. You may also want to set thestyle tohiddenwhen the modal is open, and reset it toauto when the modal is closed:function disableFullPageScroll() { $.fn.fullpage.setAllowScrolling(false); $.fn.fullpage.setKeyboardScrolling(false); document.body.style.overflow = 'hidden'; } function enableFullPageScroll() { $.fn.fullpage.setAllowScrolling(true); $.fn.fullpage.setKeyboardScrolling(true); document.body.style.overflow = 'auto'; }