Good day! When you open the default page there is a condition to cancel the scroll.

function OffScroll () { var winScrollTop = $(window).scrollTop(); $(window).bind('scroll',function () { $(window).scrollTop(winScrollTop); });} OffScroll (); 

How can I restore the ability to scroll the page when I click on the <div class="open">Блок</div> ? Thanks for the help!

    1 answer 1

    The unbind () function to help you:

     $(window).unbind('scroll'); 

    UPD . Added an example:

     function OffScroll() { var winScrollTop = $(window).scrollTop(); $(window).bind('scroll', function() { $(window).scrollTop(winScrollTop); }); } OffScroll(); $(document).ready(function() { $('.open').click(function() { $(window).unbind('scroll'); }); }); 
     .block { height: 1200px; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button class="open">Unbind</button> <div class="block"></div> 

    • That way? $ (function () {$ ('. open'). click (function () {. unbind ('scroll')};}); But that doesn't work. What am I doing wrong? - LADYX
    • one
      @LADYX, added an example, look, scrolling is prohibited in the "Result" window and the button works again, and the code seems to lack $(window) before unbind() - MasterAlex
    • Yes, of course everything works, but at the same time other scripts related to scrollTop, such as scrolling to the top of the page, stop working. Strange, why the conflict, if we press the block, we restore the scroll functions? - LADYX
    • one
      @LADYX, this function does not restore the scroll function, but cancels all the scroll handlers that you hang on the window - MasterAlex