Javascript Image zoom-in and zoom-out code

Source: Internet
Author: User

View JS source code: Copy codeThe Code is as follows: // zoom in and out control
Var PhotoSize = {
Zoom: 0, // zoom Rate
Count: 0, // Number of zooming times
Cpu: 0, // current zoom factor
Elem: "", // image Node
PhotoWidth: 0, // The initial width of the image.
PhotoHeight: 0, // The initial height of the image.

Init: function (){
This. elem = document. getElementById ("focusphoto ");
This. photoWidth = this. elem. scrollWidth;
This. photoHeight = this. elem. scrollHeight;

This. zoom = 1.2; // Set Basic parameters
This. count = 0;
This. cpu = 1;
},

Action: function (x ){
If (x = 0 ){
This. cpu = 1;
This. count = 0;
} Else {
This. count + = x; // Add record
This. cpu = Math. pow (this. zoom, this. count); // any power operation
};
This. elem. style. width = this. photoWidth * this. cpu + "px ";
This. elem. style. height = this. photoHeight * this. cpu + "px ";
}
};
// Enable the zoom-in and zoom-out effect to be loaded using the onload method to prevent the width and height of the image from being retrieved by the first click.
Window. onload = function () {PhotoSize. init ()};

We recommend that you use the onload Method for reference to read the size of the initial image.<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <meta name =" auther "content =" f7 "> <input type =" button "value =" Enlarge "onclick =" PhotoSize. action (1); "> <input type =" button "value =" "onclick =" PhotoSize. action (-1); "> <input type =" button "value =" Restore size "onclick =" PhotoSize. action (0); "> <input type =" button "value =" view current multiple "onclick =" alert (PhotoSize. cpu); "> <br/>

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.