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.

3
  • What is initializing the scrolling? Depending on the element, you could use $(element).click(function(event){ event.preventDefault(); }); Commented Sep 29, 2014 at 20:48
  • When users click on buttons it shouldn't scroll at all. I am missing information.. Commented Sep 29, 2014 at 20:48
  • Is it scrolling or page jumping you want to prevent??? Commented Sep 29, 2014 at 20:50

3 Answers 3

3

Use CSS:

body{overflow:hidden;}

jQuery:

$("button").click(function(){
  $("body").css("overflow","hidden");
});
Sign up to request clarification or add additional context in comments.

1 Comment

@BojanPetkovski It disables scrolling. I'd make a fiddle, but it won't be functional through the jsfiddle app.
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

Comments

-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.

1 Comment

This is not jQuery as the op has requested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.