让图片自适应大小的方法
<body>
<img id="achome" src="http://image2.sina.com.cn/ent/y/2006-10-09/U1819P28T3D1276435F326DT20061009152013.jpg" />
</body>
<script>
var imageArr=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>
<img id="achome" src="http://image2.sina.com.cn/ent/y/2006-10-09/U1819P28T3D1276435F326DT20061009152013.jpg" />
</body>
<script>
var imageArr=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>

浙公网安备 33010602011771号