我有一个模式,在这个模式中,有一个显示大量隐藏内容的下拉列表,这是有效的。
现在,当您打开堆叠在第一个模式之上的下一个模式并关闭它时,下方的模式滚动将被禁用。
我已经创建了一个完整的示例,包括复制我面临的问题的步骤。你可以在here上看到它。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<title></title>
<style>
</style>
</head>
<body>
<input type="button" data-toggle="modal" data-target="#modal_1" class="btn btn-lg btn-primary" value="Open Modal 1" >
<div class="modal fade" id="modal_1">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">First Modal</h4>
</div>
<div class="modal-body">
<form class="form">
<div class="form-group">
<label>1) Open This First: </label>
<input type="button" data-toggle="modal" data-target="#modal_2" class="btn btn-primary" value="Open Modal 2" >
</div>
<div class="form-group">
<label>2) Change this once you have opened the modal above.</label>
<select id="change" class="form-control">
<option value="small">Show Small Content</option>
<option value="large">Show Large Content</option>
</select>
</div>
<div id="large" class='content-div'>
<label>Large Textarea Content.. Try and scroll to the bottom..</label>
<textarea rows="30" class="form-control"></textarea>
</div>
<div id="small" class='content-div'>
<label> Example Text Box</label>
<input type="text" class="form-control">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal_2">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Second Modal</h4>
</div>
<div class="modal-body">
<hp>This is the stacked modal.. Close this modal, then chenge the dropdown menu, you cannot scroll... </h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$(".content-div").hide();
$("#change").change(function() {
$(".content-div").hide();
$("#" + $(this).val()).show();
});
});
</script>
</html>
下面是一个Bootply,用来展示实际的行为:
发布于 2015-01-21 22:01:32
这也是一种解决方案
.modal {
overflow-y:auto;
}
http://www.bootply.com/LZBqdq2jl5
Auto运行得很好:)这实际上将修复任何运行高于屏幕尺寸的模式。
发布于 2016-05-04 15:37:15
这是因为当您关闭一个模式时,它会从<body>
标记中删除modal-open
。Bootstrap不支持同一页面上的多个模态(至少在BS3之前是这样)。
让它工作的一种方法是,在关闭一个模式时使用BS触发的hidden.bs.modal
事件,然后检查是否有任何其他模式打开,以便在主体上强制modal-open
类。
// Hack to enable multiple modals by making sure the .modal-open class
// is set to the <body> when there is at least one modal open left
$('body').on('hidden.bs.modal', function () {
if($('.modal.in').length > 0)
{
$('body').addClass('modal-open');
}
});
发布于 2015-01-21 21:56:58
我已经为你找到了一个解决方案。我不确定为什么它不能工作,但是在你的CSS中只需要一行代码就可以解决这个问题。在关闭第二个模式之后,第一个模式以某种方式获得了overflow-y:hidden
。即使它实际上设置为auto
。
您需要重写此代码,并在CSS中设置您自己的声明:
#modal_1 {
overflow-y:scroll;
}
在这里,您有一个可以工作的DEMO
编辑:链接错误,抱歉。
https://stackoverflow.com/questions/28077066
复制