gpt4 book ai didi

jquery - IE 11 中的转换 + 定位问题

转载 作者:行者123 更新时间:2023-11-28 11:28:33 28 4
gpt4 key购买 nike

我在模态中有一个 position:fixed div,bootstrap 在其上应用了 transform:translate 规则。它在 FF 和 Chrome 中运行良好,但在 IE 11 中无法正确显示。

在这里你可以看到问题:http://jsfiddle.net/roahda03/23/

这是 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;
}

和在滚动时应用的 jquery

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();
});

编辑:这似乎是 a bug .我的问题是如何解决这个问题?

最佳答案

好的,我找到了一个很好的解决方案。

  • 检测使用的浏览器是否为IE
  • css 顶部替换为模态视图顶部的 offset().top
  • css 替换为 getFixed id 元素的 offset().left

这在所有 IE 浏览器和其他浏览器上都能正常工作。请尝试。

我也做了一个 fiddle :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">&times;</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&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
<p>One fine body&hellip;</p>
</div>
<div class="modal-footer">
some random buttons
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->

关于jquery - IE 11 中的转换 + 定位问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41953489/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com