I have a page with modal window, I want to in order to user could scroll divs in modal (when modal is open), but not all page, and if user close modal window he can scroll all page.
$(window).scroll(function (e) {
if (! modal ) {
e.preventDefault();
}
})
Is it possible ?
You can set body overflow property to hidden to prevent scroll. For example by adding some class to body element when popup is open:
.no-scroll {
overflow: hidden;
}
Compare scroll behavior with overflow: hidden
and auto in next demo.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.