I read a lot of solutions / hacks on this topic on StackOverflow but none of them seem to work for me.
I am using a modal for logging in in Meteor (eg. using Facebook login service). And a callback is triggered when the login is successful.
I put this in my callback to close the modal -
$('#modalSignIn').modal('toggle');
Everything works fine except that after close, there is no scrollbar on the page.
One solution I got was from here -
.modal-open {
overflow: scroll;
}
This works partially because I have the scrollbar even when the modal closes. However, there seems to be about 15px padding on the right (where the previous scrollbar should be.) On repeating this opening and closing, the padding keeps adding up.
EDIT:
Here is my Nav template -
<template name="_navMenu">
{{#if isLoggedIn}}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">My Profile <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">My Profile</a></li>
<li><a href="#">Edit Profile</a></li>
<li class="divider"></li>
<li><a href="#" id="logout-button">Logout</a></li>
</ul>
</li>
{{else}}
<li><a href="#" data-toggle="modal" data-target="#modalSignUp">SIGN UP</a></li>
<li><a href="#" data-toggle="modal" data-target="#modalSignIn">LOG IN</a></li>
<li><button class="btn btn-primary nav-button visible-xs-inline-block">Text Here</button></li>
<!-- Modal -->
<div class="modal fade" style="overflow-y: scroll;" id="modalSignIn" tabindex="-1" role="dialog" aria-labelledby="SignInLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
{{> atFormModal state="signIn"}}
</div>
</div>
</div>
</div>
</div>
{{/if}}
</template>
Approach: A simple solution to this problem is to set the value of the “overflow” property of the body element to “hidden” whenever the modal is opened, which disables the scroll on the selected element.
An alternative approach is to set the width of the html element to 100vw. On many if not most browsers, this negates the effect of scrollbars on the width. Show activity on this post. I was able to get this to work by adding it to the body tag.
You can prevent closing of modal dialog by setting the beforeClose event argument cancel value to true.
Use the . modal-dialog-scrollable class to enable scrolling inside the modal.
I had the same problem.
Bootstrap add modal-open
class in the body
, but does not remove when the modal is closed.
I solved just adding in callback:
$('body').removeClass('modal-open');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With