如何在JQuery中调整图像大小

时间:2012-06-14 05:38:30

标签: javascript jquery image

这里改变大小?我找不到合适的方法

var img = new Image();
img.src = newImg.ImagePath;

2 个答案:

答案 0 :(得分:2)

$(img).width(width_in_pixels).height(height_in_pixels);

您也可以使用$(img)代替$('selector')。如果要创建新的,请使用:

$('<img/>', {src: 'url to the image'}).width(width_in_pixels).height(height_in_pixels).appendTo('#someElement');

答案 1 :(得分:1)

100px x 100px图片。

var img    = new Image();
img.src    = newImg.ImagePath;
img.width  = 100;
img.height = 100;