Answer the question
In order to leave comments, you need to log in
How to prevent body from scrolling when opening a modal window without scrolling to the top of the page?
Hello,
There was a task to prevent the body from scrolling when opening a modal window. After digging around on the web, I found a solution to add " overflow: hidden " styles to the body , but in this case the page scrolls to the top, and I need it to stay in its position and just not scroll.
Help solve the problem in the simplest way possible. Thank you.
Answer the question
In order to leave comments, you need to log in
There is no beautiful and universal solution. There are two options, the first one will increase the page space due to the disappeared scroll, which in itself is not correct (well, you’ll get tired of looking for all elements that move down with a fixed position), and the second, correct option is possible only with a throw of the page up (this can be fixed by calculating each time the distance is scrolled and add top, but it's EVERYTHING'S UGLY).
I scored and do with scrolling. To do without scrolling is not difficult at all, but it's dirt.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question