I'm using the scrollTo jQuery plugin and would like to know if it is somehow possible to temporarily disable scrolling on the window element through Javascript? The reason I'd like to disable scrolling is that when you scroll while scrollTo is animating, it gets really ugly ;)
Of course, I could do a $("body").css("overflow", "hidden");
and then put it back to auto when the animation stops, but it would be better if the scrollbar was still visible but inactive.
Cancelling the event's as in the accepted answer is a horrible method in my opinion :/
Instead I used
position: fixed; top: -scrollTop();
below.Demo: https://jsfiddle.net/w9w9hthy/5/
From my jQuery popup project: https://github.com/seahorsepip/jPopup
This code takes, width, height, scrollbar and pagejump issues into consideration.
Possible issues resolved with above code:
If anyone has any improvements to above page freeze/unfreeze code let me know so I can add those improvements to my project.
A simple solution that worked for me (disabling window scrolling temporarily).
Based on this fiddle: http://jsfiddle.net/dh834zgw/1/
the following snippet (using jquery) will disable the window scroll:
And in your css:
Now when you remove the modal, don't forget to remove the noscroll class on the html tag:
Depending on what you want to achieve with the removed scroll you could just fix the element that you want to remove scroll from (on click, or whatever other trigger you'd like to temporarily deactivate scroll)
I was searching around for a "temp no scroll" solution and for my needs, this solved it
make a class
then with Jquery
I found that this was a simple enough solution that works well on all browsers, and also makes for simple use on portable devices (i.e. iPhones, tablets etc). Since the element is temporarily fixed, there is no scroll :)
NOTE! Depending on the placement of your "contentContainer" element you might need to adjust it from the left. Which can easily be done by adding a css left value to that element when the fixed class is active
I have the same problem, below is the way I handle it.
hope this help.
Building on Cheyenne Forbes' answer, and one I found here via fcalderan: Just disable scroll not hide it? and to fix Hallodom's issue of the scrollbar disappearing
CSS:
JS:
This code does jump you to the top of the page, but I think that fcalderan's code has a workaround.