【发布时间】:2011-08-29 04:55:28
【问题描述】:
我们有一些通过 jQuery 垂直居中对齐的图像。我们想要发生的是隐藏$(document).ready 上未对齐的图像(意思是,未居中),然后运行以window.onload 为中心的函数,然后显示图像。
当页面加载时,图像会立即在 Firefox 和 Chrome 上隐藏。但在 IE8 中,有那么一瞬间,它仍然会在隐藏之前显示未对齐的图像。
IE8 有没有办法更快/立即隐藏它们?下面是代码:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('.img_mask img').hide();
});
window.onload = function() {
$('.img_mask img').each(function() {
var $img = $(this);
var h = $img.height();
var w = $img.width();
$img.css('margin-top', +h / -2 + "px").css('margin-left',+ w/ -2 + "px");
$('.img_mask img').show();
});
【问题讨论】:
标签: javascript jquery css internet-explorer-8 show-hide