gpt4 book ai didi

javascript - 获取ajax加载图像的大小

转载 作者:行者123 更新时间:2023-11-30 10:38:46 26 4
gpt4 key购买 nike

我试过使用 $element.width()$element.height() 两者似乎都无法帮助检索 ajax 加载图像的值.我如何使用 jQuery 或常规 JS 获得这些?图像在 CSS 中没有设置。

最佳答案

当你加载内容时,在你的 ajax 成功中使用这样的东西

var real_image_sizes = {};
$('your loaded images').one('load', function() {
//get real image size
real_image_sizes.width = this.width; // Note: $(this).width() will not
real_image_sizes.height = this.height; // work for in memory images.
}).each(function() {
if(this.complete) $(this).load();
});

关于javascript - 获取ajax加载图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12406665/

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