I am using bootstrap and Parse framework to build a small webapp. But those Bootstrap modals keep adding padding-right to body after closed. How to solve this?
I tri
My solution does not require any additional CSS.
As pointed by @Orland, one event is still happening when the other starts. My solution is about starting the second event (showing the adminPanel
modal) only when the first one is finished (hiding the loginModal
modal).
You can accomplish that by attaching a listener to the hidden.bs.modal
event of your loginModal
modal like below:
$('#loginModal').on('hidden.bs.modal', function (event) {
$('#adminPanel').modal('show');
}
And, when necessary, just hide the loginModal
modal.
$('#loginModal').modal('hide');
Of couse you can implement your own logic inside the listener in order to decide to show or not the adminPanel
modal.
You can get more info about Bootstrap Modal Events here.
Good luck.
I hope there is still someone who needs this answer. There is a function called resetScrollbar() in bootstrap.js, for some stupid reason the developers decided to add the scrollbar dimensions to the body's padding right. so technically if you just set right-padding to an empty string it will fix the problem
This is what worked for me:
body.modal-open {
overflow: auto !important;
}
// Bootstrap uses JS to set the element style so you can
// override those styles like this
body.modal-open[style] {
padding-right: 0px !important;
}
(Bootstrap v3.3.7) From my browser inspector i saw that this is directly set in the element style property, witch overrides class properties.
I tryed to 'reset' the paddig-right value when the modal is showing with :
$("#myModal").on('shown.bs.modal', function(){
$(this).css({paddingRight:""});
});
But it comes back as soon as the window is resized :( (probablly from the pluggin script).
This solution worked for me :
var modal_needfix=true;
$("#myModal").on('shown.bs.modal', function(){
var modalscope=$(this);
modalscope.css({paddingRight:""});
if(modal_needfix){
window.addEventListener("resize",function(){
requestAnimationFrame(function(){// be sure to act after the pluggin script
modalscope.css({paddingRight:""});
});
});
modal_needfix=false;
}
});
With Bootstrap 4 this worked for me:
$(selector).on('hide.bs.modal', function (e) {
$('body').css('padding-right','0');
});
This can solve the problem
.shop-modal.modal.fade.in {
padding-right: 0px !important;
}