Home  >  Q&A  >  body text

How to add condition before scrolling operation

<p>I have a problem using the fullpage.js library I need the screen not to scroll when my modal opens. </p> <p>I tried to disable scrolling using onLeave, afterLoad and jQuery, the code is as follows: </p> <pre class="brush:php;toolbar:false;">$(document).ready(function () { $(window).bind("wheel", function (e) { if (document.getElementsByClassName("modalIsOpen").length != 0) { $.fn.fullpage.setAllowScrolling(false); } else { $.fn.fullpage.setAllowScrolling(true); } }); $("#fullpage").fullpage({ normalScrollElements: ".tableContainer", }); });</pre> <p>But the problem with this code is that after the page scrolls once, the page scrolling stops working. It seems that fullpage.js scrolls first and then jQuery stops scrolling. Any ideas? Thank you everyone</p>
P粉738046172P粉738046172410 days ago459

reply all(1)I'll reply

  • P粉195402292

    P粉1954022922023-09-06 13:24:23

    Thanks to @JavierFromMadrid I found the solution But this is not an exact answer to the topic question, but another way to solve the problem One way to solve this problem is to disable fullpagejs scrolling when opening the modal:

    $.fn.fullpage.setAllowScrolling(false);

    In order to prevent the called function from disabling modal box scrolling, the name of the modal box class needs to be defined in the normalScrollElements option of fullpage.

    $("#fullpage").fullpage({
        normalScrollElements: ".modal",
      });

    reply
    0
  • Cancelreply