gpt4 book ai didi

javascript - 负载在 jquery 中不起作用,请帮忙

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

我正在尝试解决我的代码中的一个 jquery 问题

<script language="javascript">
$(document).ready(function() {
//if the document is ready
$('#img').load(function() {
//if the image is loaded
pic_real_height = this.height;
//finding the height of the image
$('#img').css('margin-top', 150 - pic_real_height / 2 + 'px'); //setting the margin-top to align the image verticall middle in the container<br>
});
});
</script>

此脚本适用于除 IE 和 Opera 之外的所有浏览器,我该如何解决这个问题?其实我想在容器(div)中将图像垂直居中设置

谢谢大家

最佳答案

尝试

pic_real_height = $(this).height();

关于javascript - 负载在 jquery 中不起作用,请帮忙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3316111/

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