gpt4 book ai didi

javascript - 将子图像的宽度和高度应用于容器

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

我有这个标记:

    <div class="img_container">
<img src="file://localhost/img/a_bg.jpeg" alt="a_bg" />
</div>

如何将图像的宽度和高度应用到img_container?

图像位于绝对位置

最佳答案

未经测试,但我建议:

$('.img_container img').each(function(){
var w = this.naturalWidth,
h = this.naturalHeight;
$(this).parent().css({'height': h, 'width' : w});
});

关于javascript - 将子图像的宽度和高度应用于容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345926/

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