Fully compatible with mouse scroll and zoom Images

Source: Internet
Author: User

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 "));
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.