【发布时间】:2014-06-28 12:49:30
【问题描述】:
我在缩放 div 以适应其父级时遇到问题。这个问题似乎只出现在 Internet Explorer 中。我只在版本 9 和 11 上进行了测试,但我确信它存在于其他版本中。
每当我按照他们应该的方式缩小 div 的比例时。然而,在 Internet Explorer 中,他们将这个奇怪的空白区域留在了右侧。这似乎发生在#pageContent 内部,#formScale 的缩放似乎是问题所在。
有没有人知道为什么会发生这种情况?因为我一辈子都想不通。
注意 - 我不想通过隐藏溢出来解决这个问题
JSFiddle | JSFiddle Full Screen
这是 IE 9 窗口缩小时显示空白的图像:
HTML
<div id="pageContent">
<div id="formBox">
<div id="formScale">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
</div>
CSS
#pageContent {
width:100%;
overflow:auto;
padding-bottom:20px;
border:1px solid red;
}
#formBox { display:block;height:auto; padding:15px 10px;border-bottom:5px solid red;}
#formScale::after {
display: block;
content: '';
padding-bottom:5px;
}
#formScale
{
display:block;
position:relative;
width:940px;
left:50%;
margin-left:-470px;
-webkit-transform-origin: top center;
-moz-transform-origin: top center;
transform-origin: top center;
-ms-transform-origin: top center;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.box { height:1178px;width:940px;background-color:yellow;margin-bottom:10px; }
JS
resize();
zoomProject();
$(window).resize(function (e) {
resize();
zoomProject();
});
function resize() {
$("#pageContent").css('height', ($(window).height()-30) + 'px');
}
function zoomProject()
{
var maxWidth = $("#formBox").width(),
percent = maxWidth/930;
$("#formScale").css({
'transform': 'scale(' + percent + ')',
'-moz-transform': 'scale(' + percent + ')',
'-webkit-transform': 'scale(' + percent + ')',
'-ms-transform': 'scale(' + percent + ')'
});
}
【问题讨论】:
-
Chrome 中似乎也出现了同样的效果。比较:imgur.com/69aZobH,gNg2ECL(Chrome)与imgur.com/ptVkXOr,05r4W1F(IE)。调整窗口大小时,两者似乎都有额外的空白。
-
@Joeytie50 我特别在谈论水平空白。当窗口的宽度变小并且出现的容器右侧的空白处
-
是否有可能从非常小的元素开始,然后将所有内容放大?扩大规模不会产生这个空白,所以这可能是一个解决方案,只要它不会因某种原因使事情复杂化。
-
请问,为什么不能使用
overflow-x:hidden?在我看来,这是使用它的理想情况。 -
@Joeytje50 我在 Niet 的回答中回答了这个问题。我对结构的变化持开放态度,但我确实需要 x 卷轴。这会使我放大的很多事情变得复杂。
标签: javascript jquery css internet-explorer