Reputation: 1261
I have a position:fixed div in a modal on which bootstrap applied the transform:translate rule. It works fine in FF and Chrome but not showing up correctly in IE 11.
Here you can see the problem: http://jsfiddle.net/roahda03/23/
This is the 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);
overflow-y: scroll;
}
#getFixed {
position: relative;
left: 10px;
width: 500px;
}
and the jquery applied at scroll
jQuery(function($) {
function fixDiv() {
var $cache = $('#getFixed');
if ($('.modal-body').scrollTop() > 50)
{
$cache.css({
'position': 'fixed',
'top': '0px',
'left': '25px',
'width': '500px'
});
}
else
$cache.css({
'position': 'relative',
'top': 'auto',
'left': '10px'
});
}
$('.modal-body').scroll(fixDiv);
fixDiv();
});
EDIT: this seems to be a bug. My question is how this can be resolved?
Upvotes: 3
Views: 1819
Reputation: 5745
Ok, I have found a fine solution.
offset().top
of modal view topoffset().left
of getFixed
id elementThis work fine on all IE browser and other. Please try.
I have make a fiddle too: http://jsfiddle.net/0Lue2rsp/
$('.launchConfirm').on('click', function (e) {
$('#confirm').modal({
show: true
});
});
// variable for check if IE detected
var IfIE = false;
//Check if IE used
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
IfIE = true;
}
else
{
IfIE = false;
}
jQuery(function($) {
function fixDiv() {
var $cache = $('#getFixed');
if ($('.modal-body').scrollTop() > 50)
{
if(IfIE == true){
$cache.css({
'position': 'fixed',
'top': $(".modal-content").offset().top,
'left':$("#getFixed").offset().left,
'width': '500px'
});
}else{
$cache.css({
'position': 'fixed',
'top': '0',
'left':'25px',
'width': '500px'
});
}
}
else
$cache.css({
'position': 'relative',
'top': 'auto',
'left': '10px'
});
}
$('.modal-body').scroll(fixDiv);
fixDiv();
});
@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css' );
.modal-open .modal {
//overflow: hidden;
}
.modal-body {
height: calc(100vh);
overflow-y: scroll;
}
#getFixed {
position: relative;
left: 10px;
width: 500px;
}
<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>in the modal, not outside it.</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>
<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 class="modal-footer">
some random buttons
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
Upvotes: 3