Image amplification code

Source: Internet
Author: User

<Script language = "JavaScript">
<! --
Var srcX = 800; // source image size, which can be set as needed
Var srcY = 800;
Var bigX = 400; // preview window size, which can be set as needed
Var bigY = 400;
Var smallX = 200; // The width of the thumbnail.
Var smallY = srcY * smallX/srcX;
Var viewX = bigX/srcX * smallX; // preview range
Var viewY = bigY/srcY * smallY;
Var bl = srcX/smallX; // scale down
Var border = 1; // border
Window. onload = function (){
// Head. innerHTML = "loading images ";
Smallpic. width = smallX;
Smallpic. height = smallY;
Bigpic. width = srcX;
Bigpic. height = srcY;
View. style. width = viewX;
View. style. height = viewY;
Smallbox. style. borderWidth = border;
Bigbox. style. borderWidth = border;
If (window. event ){
Smallbox. style. width = smallpic. offsetWidth + border * 2;
Smallbox. style. height = smallpic. offsetHeight + border * 2;
Bigbox. style. width = bigX + border * 2;
Bigbox. style. height = bigY + border * 2;
} Else {
Smallbox. style. width = smallpic. offsetWidth;
Smallbox. style. height = smallpic. offsetHeight;
Bigbox. style. width = bigX;
Bigbox. style. height = bigY;
}
Move (event );
}
Function move (e ){
Document. getElementById ('bigbox'). style. display = "block ";
Var e = window. event? Window. event: e;
Var iebug = 0;
If (window. event ){
Var vX = e. offsetX-viewX/2;
Var vY = e. offsetY-viewY/2;
} Else {
Var vX = e. pageX-viewX/2-smallbox. offsetLeft-border;
Var vY = e. pageY-viewY/2-smallbox. offsetTop-border;
Iebug = 2;
}
If (vX <0) vX = 0;
If (vY <0) vY = 0;
If (vX> smallX-viewX-iebug) vX = smallX-viewX-iebug;
If (vY> smallY-viewY-iebug) vY = smallY-viewY-iebug;
Bigpico. style. marginLeft =-vX * bl
Bigpico. style. marginTop =-vY * bl
View. style. left = vX + smallbox. offsetLeft + border;
View. style. top = vY + smallbox. offsetTop + border;
}

Function aa (){
Document. getElementById ('bigbox'). style. display = "none ";

}
Function bb (){
Document. getElementById ('view'). style. border = "1px solid # CC9999 ";
}
// -->
</Script>
<Style type = "text/css">
<! --
* {Padding: 0; margin: 0}
Img {display: block ;}
# Smallbox {border: 1px # c33 solid; float: left; overflow: hidden; margin-top: 10px ;}
# Bigbox {border: 1px # c33 solid; overflow: hidden; position: absolute; left: 280px; top: 100px ;}
# View {position: absolute ;}
// -->
</Style>
<Div id = "smallbox"> </div>
<Div id = "bigbox"> <div id = "bigpico"> </div>
</Div>
<Div id = "view" onmousemove = "move (event)" onMouseOut = "aa ()" onMouseOver = "bb ()"> </div>

Related Article

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.