I have a script that is disabling the scrolling of the body element when I have a popup box showing, however I do not want to disable scrolling for the popup box, (or any other scrollbars other than the main body one), I have established what I want by selecting the element inside the popup box, however I want it to work for everything, not just that one element.
$('html').on('mousewheel DOMMouseScroll', "body", function(e) {
var scrollTo = null;
if (e.type == 'mousewheel') {
scrollTo = (e.originalEvent.wheelDelta * -1);
}
else if (e.type == 'DOMMouseScroll') {
scrollTo = 40 * e.originalEvent.detail;
}
if (scrollTo) {
e.preventDefault();
$(this).scrollTop(scrollTo + $(this).scrollTop());
}
});
$('div').on('mousewheel DOMMouseScroll', ".photos", function(e) {
e.stopPropagation();
});
So what I want to do is for this second script, instead of selecting .photos directly, just selecting any child of < body>
Try using the >
child selector and don't use a selector on the delegate node set.
$('body > *').on('mousewheel DOMMouseScroll', null, function(e) {
e.stopPropagation();
});
If you want any descendant of body
then remove the >
rule.
EDIT:
The previous code used a selector, which would have invalidated the delegation. Thanks @RichardNeilIlagan for pointing that out.
EDIT 2:
If you want to scroll nothing other than the contents in the popup box, why not have your popup use a 100% W x 100% H overlay like a jQuery UI dialog does in "modal" mode? Then you could attach your no-scroll handler to the full-window overlay and stopPropagation
there, couldn't you. That would work unless you require the contents behind the popup to still be accessible.