My goal is to prevent the body from scrolling when my fullscreen overlay navigation is open. I have added a class show-nav
to the body with the CSS attribute overflow: hidden
, which works perfectly on desktop but not on iPhones.
After researching similar issues on stackoverflow, I attempted using e.preventDefault()
, which did stop the scrolling but then kept the body unscrollable even after closing the navigation menu. How can I allow scrolling again when the navigation menu is closed?
$( "button.navbar-toggle" ).on( "click", function(e) {
$('body').on('touchmove', function (e) {
e.preventDefault();
});
$('html').toggleClass('show-nav');
$('body').toggleClass('show-nav');
});