Awaz Samad
Awaz Samad

Reputation: 35

How do I use disable scrolling on click in jQuery?

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

Answers (3)

jsfrocha
jsfrocha

Reputation: 1860

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.

Upvotes: -1

Rahul Dess
Rahul Dess

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

Control Freak
Control Freak

Reputation: 13213

Use CSS:

body{overflow:hidden;}

jQuery:

$("button").click(function(){
  $("body").css("overflow","hidden");
});

Upvotes: 3

Related Questions