gpt4 book ai didi

php - 如何确定图像何时完成加载?

转载 作者:行者123 更新时间:2023-11-30 18:39:11 25 4
gpt4 key购买 nike

我有一段 php 代码可以随机加载图像。我正在尝试确定图像何时加载,以便我可以对其执行一些额外的操作。这是我当前加载图片的方式:

// Gets my image
$sql = "SELECT id FROM images WHERE user_id=$owner_user_id LIMIT 0,1";
$imgres = mysql_query($sql);
if ($imgres) {
$imgrow = mysql_fetch_array($imgres, MYSQL_ASSOC);
if (!empty($imgrow)) {
echo ('<image src="img.php?id=' . $imgrow['id'] . '" id="profile_img" style="visibility:hidden"/>');
}
}

我需要做的其中一项操作是获取图像的宽度。我得到这样的图像:

alert("IMAGE WIDTH:"+$('#profile_img').width());

它当前返回 0,因为它在加载图像之前被调用。我已经尝试将此方法调用添加到我的 document.ready block 中,但它仍然会在加载图像之前被调用。有没有一种简单的方法可以确定图像何时加载?

最佳答案

$(document).ready(function(){
$('#img_id').load(function() {
alert('image is loaded');
});
});

这样就可以了

关于php - 如何确定图像何时完成加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7362630/

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