实现滚动滚轮放大缩小图片,鼠标中键放大缩小图片
<script type=”text/javascript”>
function wheel_zoom_img(id){
var tu = document.getElementById(id);
tu.onmousewheel = f;
try {
tu.addEventListener(\’DOMMouseScroll\’,f,false);
}
catch(e){}
function f(){
sctop = document.documentElement.scrollTop;
var Firefox = navigator.userAgent;
if(Firefox.indexOf(“Firefox”) == -1) {
var aa = event.wheelDelta;
}
else {
var aa = arguments[0].detail;
aa = -aa;
}
if(aa>0) {
tu.width = tu.offsetWidth*1.05;
tu.height = tu.offsetHeight*1.05;
document.documentElement.scrollTop = sctop;
}
if(aa<0) {
if(this.offsetWidth<50||this.offsetHeight<50) {
return;
}
tu.width = tu.offsetWidth/1.05;
tu.height = tu.offsetHeight/1.05;
document.documentElement.scrollTop = sctop;
}
}
}
window.onload = function() {
wheel_zoom_img(“tu0”);
}
</script>
</head>
<body>
<img src=”yw.jpg” id=”tu0″ />