Reputation: 35
Trying to disable scrolling if the user clicks a button. I have tried:
$(window).bind('scroll');
Inside a click function, but that doesn't work. Could someone help me? I have looked around and couldn't find a straight answer or a working solution.
Upvotes: 1
Views: 17526
Reputation: 1860
The following JSFiddle snippet also disables scrolling through the Arrow Keys or PageUp/Down Keys:
Mainly the method:
(...)
function disable_scroll() {
if (window.addEventListener) {
window.addEventListener('DOMMouseScroll', wheel, false);
}
window.onmousewheel = document.onmousewheel = wheel;
document.onkeydown = keydown;
}
(...)
Reference here.
Upvotes: -1
Reputation: 2587
You can try with this
$("button").click(function(){
$(".div").css({
'overflow' : 'hidden',
'height' : '100%'
});
});
This answer is reference from How to programmatically disable page scrolling with jQuery
Upvotes: 0
Reputation: 13213
body{overflow:hidden;}
$("button").click(function(){
$("body").css("overflow","hidden");
});
Upvotes: 3