ITeye博客

图片大小自适应

netxdiy · 2007-06-11 23:41 · Markdown

<body>
<imgid="achome"src="http://image2.sina.com.cn/ent/y/2006-10-09/U1819P28T3D1276435F326DT20061009152013.jpg"/>
</body>

<script>
//取得img元素
varimageArr=document.getElementById("achome");

alert("图片原始大小为550x734");

//图形的宽/高比
imageRate=parseInt(imageArr.style.width)/parseInt(imageArr.style.Height);

//
if(imageArr.offsetWidth>200)
{
alert("现在使图片自适应大小...");
imageArr.style.width="200px";
imageArr.style.height=200/imageRate+"px";
}
</script>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。