javascript - Jquery/JS : How to prevent scrolling in parent element while the child is scrollable (mobile)? -
i need enable scrolling in child element , disable parent elements. default when child scrolling on parent starts scroll, wish prevent default.
i wrote following code , don't understand why wrong
document.body.addeventlistener('touchmove', function(e){ if (body.hasclass('sliding-menu-open')) { if (e.target.id == 'masc') { e.preventdefault(); } else{ e.stoppropagation(); } } }); in other words, if body has 'sliding-menu-open' class , target's id not 'masc', prevent scrolling ability of parents.
i sure e.stoppropagation() trick, doesn't.
anyone?
edit: i've created new sidebar website, fixed top right. has lot of content, therefore need scrollable. when sidebar open want prevent content of page scroll.
hope it's clear enough understand problem.
answer:
solution adding overflow: hidden, problem have been adding css body, parent or document, when should add 'html' tag.
thank's help!
try adding overflow:hidden on parent element when body has class sliding-menu-open
.sliding-menu-open .parent { overflow:hidden; } if need more help, please provide example of html structure or example jsfiddle
Comments
Post a Comment