width = img.width * (size[i-1] / 100);
height = img.height * (size[i-1] / 100);
确实有问题,你的图片最大化后,再点小,这时size[i-1]=size[5]=150
width = img.width * (size[i-1] / 100);等于把图片扩大了1.5倍。
height = img.height * (size[i-1] / 100);
确实有问题,你的图片最大化后,再点小,这时size[i-1]=size[5]=150
width = img.width * (size[i-1] / 100);等于把图片扩大了1.5倍。
<html>
<title>画像</title>
<body >
画像<br>
<img src="COWBOY01.JPG name="org1" border=1 >
<hr><BR>
<input type="button" name="prev" value="大" onClick="imgSize(true)">
<input type="button" name="next" value="小" onClick="imgSize(false)">
</body>
</html>
<script language="JavaScript">
<!--
var now = '100';
var i=4;
var img = document.images[0];
var oldwidth=img.width;
var oldheight=img.height;function imgSize(isContent)
{
var size = new Array('10','25','50','75','100','150','205');if(isContent)
{
if(now == '205')
{
alert("最大了");
return;
}
else
{
i++;
now=size[i]
width = oldwidth * (now / 100);
height = oldheight * (now / 100);
}
}
else
{
if(now == '10')
{
alert("最小了");
return;
}
else
{
i--;
now=size[i];
width = oldwidth * (now / 100);
height = oldheight * (now / 100);
}
} document.images[0].width = width;
document.images[0].height = height;}
-->
</script>
<input type="button" value="+"
onmousedown="timer1=setInterval('mypic.width++;',30)"
onmouseup="clearInterval(timer1)">
<input type="button" value="-"
onmousedown="timer1=setInterval('mypic.width--;',30)"
onmouseup="clearInterval(timer1)">
<br>
<img src="http://community.csdn.net/images/CSDN_logo.GIF" id="mypic">
height;
在按钮点击交替时并非变了原值,