I am currently using twitter bootstrap 3 modal on mobile. It works perfectly fine on desktop, however on mobile whenever I scroll it also scrolls the window behind the modal. How do I prevent this from happening?
相关问题
- How to add a “active” class to a carousel first el
- Full Clickable Accordion in Bootstrap
- Get value of selected option using jquery [duplica
- How to add Bootstrap 4 without Tether?
- Laravel overriding bootstrap template
相关文章
- Twitter Bootstrap Prints In XS
- Make Bootstrap tab Active on the bases of URL link
- Rails: Twitter Bootstrap Buttons when visited get
- Reduce spacing between rows
- How do use bootstrap tooltips with React?
- Need to design 8 boxes in two rows
- Why should I start using Google Material Design Li
- How to disable content based on checkbox in Angula
This works for me!
FOR BOOTSTRAP 3
I found a fix for this issue that seems to be good enough for my site.
CSS:
HTML:
So in the case that a modal is open, all non-modal content is limited to the height of the viewport and overflow is hidden, which prevents the main site from being scrolled, while the modal can still be scrolled.
EDIT: This fix has some issues in Firefox.
Fix for my site was (FF only media query):
For Bootstrap 3
I found a solution for mobile devices (touch screen) with iscroll.js
in the content of the modal add:
To initialize on .js
I have noticed that it only scrolls the background page when in the modal your scrolling and you hit the bottom of the modal, then if you try to keep scrolling down it scrolls the background page. Look to the right side overflow bar, it just visible when the modal is open (on Chrome-Android)
Seems like the effect is to scroll the modal to the extent of modal, then automatically scroll the background page even though the modal is still open.
Hey guys so i think i found a fix for Bootstrap 3. This is working for me on iphone and android at the moment. Its a mash up of hours upon hours of searching, reading and testing. So if you see parts of your code in here credit goes to you lol.
The reason the media specific is on there is on a desktop i was having issues with when the modal would open all content on the page would shift from centered to left. Looked like crap. So this targets up to tablet size devices where you would need to scroll. There is still a slight shift on mobile and tablet but its really not much. Let me know if this works for you guys. Hopefully this puts the nail in the coffin
Yea this was super annoying when I came across this issue on my iphone 6s today.
This still seems to be an issue, even with the latest bootstrap (3.3.6 at my moment).
CSS Quickfix Solution:
"Note that this has the side-effect of "scrolling" to the top of the page while the modal is open."
See more details about this solution here
Javascript/jQuery Solution:
A better solution would be to utilize bootstrap's modal events. This solution integrates the quickfix method, but fixes the 'top of page' problem. You can then alter the css as needed depending on the event.
In my code below, I set the current position of the window on the event
show.bs.modal
(this value is used to fix the 'quickfix' problem).I then apply the css quick fix on the
shown.bs.modal
event. In other words, after the modal pops up.Finally, when the modal is closed, I switch the body's position to relative (can be set to static as well I believe) and scroll the window back to its original position.
Should be relatively simple to set up for anyone with some javascript experience.
Hopefully they will solve this issue in bootstrap 4, but until then, hope this answer helps out other people with similar problems.