The code is as follows:
/*!
*author: Code implemented in javascript that is fully compatible with mouse scroll wheel zooming of images_javascript skills
*blog:http://www.cnblogs.com/Code implemented in javascript that is fully compatible with mouse scroll wheel zooming of images_javascript skills
*date:2010-2-4
*/
var zooming=function(e){
e= window.event ||e;
var o=this,data=e.wheelDelta || e.detail*40,zoom,size;
if(! 'v1'){
zoom = parseInt( o.style.zoom) || 100;
zoom = data / 12;
if(zoom > zooming.min)
o.style.zoom = zoom '%';
}else {
size=o.getAttribute("_zoomsize").split(",");
zoom=parseInt(o.getAttribute("_zoom")) ||100;
zoom =data/12 ;
if(zoom>zooming.min){
o.setAttribute("_zoom",zoom);
o.style.width=size[0]*zoom/100 "px";
o.style.height=size[1]*zoom/100 "px";
}
}
};
zooming.add=function(obj,min){//First Each parameter specifies the image that can be zoomed, min specifies the minimum zoom size, default to 50
zooming.min=min || 50;
obj.onmousewheel=zooming;
if(/a/[-1 ]=='a')//if Firefox
obj.addEventListener("DOMMouseScroll",zooming,false);
if(-[1,]){//if not IE
obj.setAttribute ("_zoomsize",obj.offsetWidth "," obj.offsetHeight);
}
};
window.onload=function(){//Put it in onload, otherwise it will not be in ie There will be an error in calculating the image size
zooming.add(document.getElementById("testimg1"));
}
Demo code
]
ps: Because this page has Scroll bar, so if it is placed directly on the page, the page will scroll instead of the picture. I don’t know if there is any solution.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn