gpt4 book ai didi

jquery - IE 错误 - 尝试获取图像的宽度/高度并为其提供 margin-top 和 margin-left

转载 作者:太空宇宙 更新时间:2023-11-04 16:13:37 25 4
gpt4 key购买 nike

我的页面底部有这段代码,用于在页面上按比例将一些图像居中。它在 Firefox 和 Chrome 中运行良好,但在 IE 中却不行。它确实在 IE 中执行 fadeIn(2000); 但它不会移动图像。这是一个 IE 错误吗?有什么建议吗?

    <script>
jQuery.noConflict();
$j(window).load(
function () {

$j('#featured img').each(
function () {
var theWidth = $j(this).width();
var theHeight = $j(this).height();

$j(this).css({ 'margin-top': -theHeight / 2 + 'px',
'margin-left': -theWidth / 2 + 'px' });
});
$j("#featured img").fadeIn(2000);
});

编辑

 <div id="featured"><a href="mysite.com" target="_blank"><img src="myimage.jpg" id="Image38" /></a></div>
<div style="clear: both;"></div>
<div style="background-color: #e4e4e4; margin-top: 20px;">
<div id="featured"><a href="mysite.com" target="_blank"><img src="myimage.gif" id="Image1" /></a></div>
<div style="clear: both;"></div>
<div id="featured"><img src="myimage.jpg" id="Image2" /></div>
<div style="clear: both;"></div>

最佳答案

似乎对我来说工作正常,在 IE/FF/CHROME 中...参见:http://jsfiddle.net/2QCFM/

$('#featured img').each(
function () {
var theWidth = $(this).width();
var theHeight = $(this).height();

$(this).css({ 'margin-top': -theHeight / 2 + 'px',
'margin-left': -theWidth / 2 + 'px' });
alert('width:' + theWidth + ' height:'+ theHeight);
});
$("#featured img").fadeIn(2000);

关于jquery - IE 错误 - 尝试获取图像的宽度/高度并为其提供 margin-top 和 margin-left,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7932820/

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