用滚轮实现图片缩放
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用滚轮实现图片缩放</title>
</head>
<script language="JavaScript">
function zoomimg(img){
//img.style.zoom获取img对象的缩放比例,并转为十进制整数
var zoom = parseInt(img.style.zoom,10);
if (isNaN(zoom)){ //当zoom非数字时zoom默认为100%
zoom = 100;
}
//event.wheelDelta滚轮移动量上移+120,下移-120;显示比例每次增减10%
zoom += event.wheelDelta / 12;
//当zoom大于10%时重新设置显示比例
if (zoom>10) img.style.zoom = zoom + "%";
}
</script>
<body>
<br>
<!--onmousewheel:当滚轮移动时触发-->
<img src="001.gif" onmousewheel="zoomimg(this)">
</body>
</html>
Trackback: http://tb.blog.youkuaiyun.com/TrackBack.aspx?PostId=526474
本文介绍了一种使用鼠标滚轮来调整图片大小的方法。通过JavaScript实现,根据滚轮的上下滚动改变图片的缩放比例,提供了简单易用的交互体验。
1204

被折叠的 条评论
为什么被折叠?



