[英]Is there a better way to update the height and width of an image with jquery?
I have to update the image height and width after dynamically loading a new thumb. 动态加载新拇指后,我必须更新图像的高度和宽度。 I'm currently doing it like so:
我现在这样做:
...
$('#thumb_' + newID).attr('width', 120);
$('#thumb_' + newID).attr('height', 120);
$('#thumb_' + newID).attr('src', data.thumb + '?v=' + ( new Date() ).getTime());
It seems like the height and width are always getting set but the image doesn't always fit the dimensions specified. 似乎高度和宽度总是被设置,但图像并不总是符合指定的尺寸。
Is there a better more reliable way to do this? 有更好的更可靠的方法吗?
try this; 尝试这个; with the css function instead of the attr function after changing the source
更改源后使用css函数而不是attr函数
var newsource=data.thumb + '?v=' + ( new Date() ).getTime();
$('#thumb_' + newID).attr('src', newsource).css({height : 120, width : 120});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.