#foo {width: 300px; height: 400px; overflow: hidden;}
<div id="foo"></div>
this.someimage = randomImageUrl;
$("foo").innerHTML = "<img src='"+this.someimage+"' class='fooimage' />";
现在,图片可能是200x200或1100x400 ...它是完全随机的。我可以伸展它(或减少其大小)使用:调整图像以适合其容器
.fooimage {width: 300px; height: 400px;}
$("foo").innerHTML = "<img src='"+this.someimage+"' class='fooimage' />";
或者,我可以测试它的大小:
imgHeight = newImg.height;
imgWidth = newImg.width;
...也许是这样的:
if(imgHeight >400){
$("foo").innerHTML = "<img src='"+this.someimage+"' height='400' />";
}
和浏览器将完成剩下的工作。
但是一定有更好的东西。有任何想法吗?谢谢! :)
很好用 - 谢谢。 – 2010-03-09 04:11:37