Hi is it possible to disable window scrolling without using overflow:hidden;
when i'm hover an element?
i tryed :
$('.chat-content').on('mouseenter',function(){
$(document).scroll(function(e){
if(!$(e).hasClass('.chat-content'))
e.stopPropagation();
e.preventDefault();
});
});
i mean, i want to leave visible the scrollbar but when i scroll out of the element i'm over with mouse the window doesn't scrolls, while the element i'm over can scroll
So disable scroll for body but not for element i'm over without using css
here is another try i did: http://jsfiddle.net/SHwGL/
tfe answered this question in another post on StackOverflow: Answered
Another method would be to use:
But it may prevent some of the jquery mobile functionality from working properly.
Plenty of good ideas on this thread. I have a lot of popups in my page for handling user input. What I use, is a combination of disabling the mousewheel and hiding the scrollbar:
Advantage of this is we stop the user from scrolling in any possible way, and without having to change css position and top properties. I'm not concerened about touch events, since touch outside would close the popup.
To disable this, upon closing the popup I do the following.
Note, I store a reference to my disableScrollFn on the existing object (in my case a PopupViewModel), for that gets triggered upon closing the popup to have access to disableScrollFn.
Following Glens idea, here it goes another possibility. It would allow you to scroll inside the div, but would prevent the body to scroll with it, when the div scroll ends. However, it seems to accumulate too many preventDefault if you scroll too much, and then it creates a lag if you want to scroll up. Does anybody have a suggestion to fix that?
You can use jquery-disablescroll to solve the problem:
$window.disablescroll();
$window.disablescroll("undo");
Supports
handleWheel
,handleScrollbar
,handleKeys
andscrollEventKeys
.If you want to scroll the element you're over and prevent the window to scroll, here's a really useful function :
Apply the class "Scrollable" to your element and that's it!
Without external variables: