Reputation: 1276
I have two pages and on one page I need to have disabled scrolling and on the other page enabled, but when I try to do that with jQuery the whole screen shakes and it is almost impossible to scroll.
This is how I did it in the script:
$(document).ready(function () {
if (window.location.pathname = '/all') {
$('body').css('overflow-y', 'auto');
} else {
$('body').css('overflow-y', 'hidden');
}
});
Is there an other way which would work to do the same thing?
Upvotes: 0
Views: 73
Reputation: 451
I think the problem is with the single equals sign in the if
statement.
Upvotes: 1
Reputation: 252
You can use preventDefault
on scroll events.
$(window).on('mousewheel DOMMouseScroll', (e) => e.preventDefault())
If you also need to block down and up keys you also need to capture the keypress event on the $(window)
and preventDefault
them.
Upvotes: 0