Bootstrap Modal Base
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<div class="page-container">
<div class="container">
<br />
<button type="button" class="btn launchConfirm">Open modal</button>
</div>
</div>
<div class="modal fade" id="confirm">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body" id="confirm2">
<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 id="getFixed" style="background-color:red">This div should be fixed<br>and should not scroll away.</div>
<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>
...
CSS
@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css' );
.modal-open .modal {
//overflow: hidden;
}
.modal-body {
height: calc(100vh - 126px);
overflow-y: scroll;
}
#getFixed {
position: relative;
left: 10px;
width: 600px;
}
JavaScript
$('.launchConfirm').on('click', function (e) {
$('#confirm').modal({
show: true
});
});
jQuery(function($) {
function fixDiv() {
var $cache = $('#getFixed');
if ($('.modal-body').scrollTop() > 50)
{
$cache.css({
'position': 'fixed',
'top': '0px',
'left': '25px',
'width': '600px'
});
}
else
$cache.css({
'position': 'relative',
'top': 'auto',
'left': '10px'
});
}
$('.modal-body').scroll(fixDiv);
fixDiv();
});