gpt4 book ai didi

javascript - 如何定义从服务器加载的图像的大小,例如宽度和高度

转载 作者:行者123 更新时间:2023-12-03 12:35:29 24 4
gpt4 key购买 nike

我已成功从服务器加载图像并将其显示到 div 元素。但我想调整图像大小,因为它很大。我该怎么做。这是我从服务器加载图像的代码。

var img = $("<img />").attr('src', url)
.load(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
alert('broken image!');
} else {
$("#image").append(img);
}
});

最佳答案

您可以使用 width()height() getter 和 setter。

var xDimension=150;
$(img).load(function(){
// put your logic here
}).width(xDimension).height(xDimension);

关于javascript - 如何定义从服务器加载的图像的大小,例如宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23751830/

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