1

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.

Awaz Samad
  • 37
  • 1
  • 1
  • 5

3 Answers3

3

Use CSS:

body{overflow:hidden;}

jQuery:

$("button").click(function(){
  $("body").css("overflow","hidden");
});
Control Freak
  • 12,107
  • 25
  • 83
  • 138
0

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

Community
  • 1
  • 1
Rahul Dess
  • 1,839
  • 1
  • 16
  • 35
-1

The following JSFiddle snippet also disables scrolling through the Arrow Keys or PageUp/Down Keys:

JSFiddle

Mainly the method:

(...)

function disable_scroll() {
  if (window.addEventListener) {
      window.addEventListener('DOMMouseScroll', wheel, false);
  }
  window.onmousewheel = document.onmousewheel = wheel;
  document.onkeydown = keydown;
}

(...)

Reference here.

Community
  • 1
  • 1
jsfrocha
  • 1,741
  • 2
  • 19
  • 29