Previously seen are with IE zoom, So non IE is not supported, yesterday saw this Js in the mouse wheel event details, so fully compatible (IE6-8, FF, chrome, opera, Safari) the scroll and zoom effect of the mouse is born today.
The default minimum scaling is 50% of the original image.
View results in a new window
The Code is as follows:
/*!
* Author: sohighthesky
* Blog: http://www.cnblogs.com/sohighthesky
* 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') {// IE
Zoom = parseint (O. style. Zoom) || 100;
Zoom + = data/12;
If (zoom> zooming. min)
O. style. Zoom = zoom + '% ';
E. returnvalue = false;
} 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"
} E. preventdefault (); // block the default behavior E. stoppropagation (); // For firefox3.6
}
};
Zooming. Add = function (OBJ, min) {// The first parameter specifies the image that can be scaled, and Min specifies the minimum zoom size, default to 50
Zooming. min = min | 50;
OBJ. onmousewheel = zooming;
If (/Firefox/. Test (navigator. useragent) // 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, the image size cannot be calculated in non-ie, and an error occurs.
Zooming. Add (document. getelementbyid ("testimg1 "));
}