图像尺寸自动缩小 [英] image size reduced automatically
问题描述
我正在j查询中寻找代码,以减小图像大小以减小其在同一网站上不同位置的大小(例如,如果您看到facebook,则左上面板的个人资料图像很大,并且图像缩小了)大小,当此图像带有注释框出现时.).
I am looking for a code in j-query , regarding image size reducing its size at different place on the same website (e.g. if you see facebook, the profile image of individual at left top panel is big and same image is reduced in size when this image appears with comment box) .
推荐答案
您可以简单地执行
myImage.attr("width", newWidth);
//or
myImage.attr("height", newHeight);
,其中myImage
是DOM与您img
元素相对应的对象.如果在HTML和HTML中的JavaScript代码中仅更改了width
或仅更改了height
(或者更好的是,在HTML中均未定义width
或height
),则将保留相同的纵横比;否则,将保持不变.它由图像的自然"尺寸定义.
where myImage
is the DOM object corresponding to you img
element. If you change only width
or only height
in both JavaScript code in and in HTML (or better yet, neither width
nor height
is defined in HTML), the same aspect ratio is preserved; it is defined by the "natural" dimensions of the image.
这篇关于图像尺寸自动缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!