When I trigger a modal view in my page it triggers the scroll bar to disappear. It's an annoying effect because the background page starts moving when the modal moves in / disappears. Is there a cure for that effect?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Thank God I came accross this post! I was pulling my hair out trying to figure how to get my scrollbars back when closing the window using my own close link. I tried the suggestions for CSS but it just wasnt working properly. After reading
I came up with a solution using jquery, so incase anyone else has the same issue and the above suggestions dont work --
the bootstrap modal adds a padding once it opens so you can try this code in your own css
I used
In this case you avoids to display the horizontal scroll bar
I think that inherit is better than scroll because when you open modal, it will always open with scroll, but when you don't have any scrolls you will get the same problem. So I just do this:
I was just playing with this 'feature' of Bootstrap modals. Seems the
.modal
class hasoverflow-y:auto;
So the modal wrapper gets his own scrollbar when the modal itself becomes to high.If you always want a scrollbar (designers often do) First set the body
Then handle
.modal-open
Leave scrollbar disabling on body untouched in this case
All other answers on this page kept making my content jump.
Heads up!
Allthough this solution worked for me all the time, yesterday I had a problem using this fix when the modal is draggable and to large to fit the screen (vertically). It might have something to do with
position:sticky
elements I added?This is a feature, class
modal-open
gets added to the HTMLbody
when you show the modal, and removed when you hide it.This makes the scrollbar disappear since the bootstrap css says
You can override this by specifying
in your own css.