js图片按指定比例缩放代码是非常实用的,我们主要是在网页面显示时会看到,如是一张图片大太了,所以得按比例进行处理了,下面的代码就是这个功能。
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>onMouseWheel</TITLE>
<SCRIPT>
var count = 10;
function Picture()
{
count = Counting(count);
Resize(count);
return false;
}
function Counting(count){
if (event.wheelDelta >= 120)
count++;
else if (event.wheelDelta <= -120)
count--;
return count;
}
function Resize(count){
oImage.style.zoom = count + '0%';
oCounter.innerText = count + '0%';
}
</SCRIPT>
</HEAD>
<BODY>
<div align=center>
<span style="font-weight:bold">Size =
<span id="oCounter" style="color:red;">100%</span></span>
<img id="oImage" src="www.111cn.net/aaa.gif" onmousewheel="return Picture();" >
</div>
</BODY>
</HTML>