cha*_*a90 1 html css jquery css-position twitter-bootstrap
我想在引导模态中修复一个元素,position: fixed但是在滚动时会随模态一起移动。我希望它即使在滚动模态后也能保持在它的位置。
这是JSFiddle。在这里,您将看到Patate文本具有position: fixedcss属性,但是如果模式很大,它将随其一起移动。我如何才能将此文本固定在其位置,以便即使滚动模式也可以将其保持在其位置。
我没有运气。请帮忙。谢谢。
这可能会有所帮助。使用模态内部的网格将固定div与其余内容分开。
$('.launch-scroll').on('click', function(e) {
$('#modal-scroll').modal({
show: true
});
});Run Code Online (Sandbox Code Playgroud)
.modal {
overflow: hidden;
}
.modal .modal-body {
height: 500px;
overflow: auto;
}
.modal .modal-fixed {
position: fixed;
background-color:red;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="page-container">
<div class="container">
<br />
<button type="button" class="btn launch-scroll">Launch Confirm</button>
</div>
</div>
<div class="modal fade" id="modal-scroll">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-2">
<div class="modal-fixed">Patate</div>
</div>
<div class="col-xs-10">
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
<p>One fine body…</p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->Run Code Online (Sandbox Code Playgroud)