我正在使用bootstrap和Parse框架来构建一个小型Webapp。但是那些Bootstrap模态在关闭后会继续向主体添加padding-right。如何解决呢?
我试图将此代码放在我的JavaScript中:
$('.modal').on('hide.bs.modal', function (e) {
$("element.style").css("padding-right","0");
});
但这是行不通的。有人知道如何解决此问题吗?
我的代码:
<button type="button" class="btn btn-lg btn-default" data-toggle="modal" data-target="#loginModal">Admin panel</button>
<div id="loginModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content -->
<div class="modal-content">
<!-- header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Login</h4>
</div>
<!-- body -->
<div class="modal-body text-center" >
<input class='form-control' type="text" id="userName" placeholder="Username" ng-model='username'>
<input class='form-control' type="password" id="password" placeholder="Password" ng-model='password'>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="loginButton" ng-click="goToAdminPanel()">Login</button>
<button type="button" class="btn btn-default" data-dismiss="modal" id="closeButton">Close</button>
</div>
</div>
</div>
</div>
</div>
<div id="adminPanel" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content -->
<div class="modal-content">
<!-- header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Admin Panel</h4>
</div>
<!-- body -->
<div class="modal-body" >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="saveButton">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal" id="closeButton">Close</button>
</div>
</div>
</div>
</div>
$scope.goToAdminPanel = function(){
Parse.User.logIn($scope.username,$scope.password,{
success: function(user){
$('#loginModal').modal('hide');
$('#adminPanel').modal();
},
error: function(user, error) {
alert('Wrong username and/or password');
}
});
}
我正在使用bootstrap和Parse框架来构建一个小型Webapp。但是那些Bootstrap模态在关闭后会继续向主体添加padding-right。如何解决呢?
modal-open
,padding-right:0 !important;
但它不起作用,你知道为什么吗?
padding-right
正确的事件上触发css属性更新,但是在错误的元素上触发它。需要在body
元素上触发它。请在下面查看我的答案。
padding-right
,但也添加类作为modal-open
用于overflow: hidden
它只是用于隐藏滚动条。