How to disable scrolling when modal is open - Full Page JS
P粉090087228
P粉090087228 2023-08-18 00:15:20
0
1
374

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.

×

At our company, we have a passion for woodworking and it shows in all of our fabrication and interior design projects. We specialize in creating custom wood furniture, fixtures and accents that are as functional as they are beautiful
P粉090087228
P粉090087228

reply all (1)
P粉805535434

The code you provided seems correct to disable scrolling when the modal is opened. However, there are several possible causes of the problem:

  1. The button that opens the modal box does not use theopenModalfunction 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:
  1. Thetag that closes the modal box does not use thecloseModalfunction. It should look like this:
×
  1. 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:
window.closeModal = closeModal;
    The
  1. 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.

  2. ThepreventDefaultandstopPropagationmethods in a scroll event handler may not be sufficient to prevent scrolling in all cases. You may also want to set the

    overflowstyle tohiddenwhen the modal is open, and reset it toauto when the modal is closed
  3. 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'; }
Please try these suggestions and let me know if they solve your problem.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!