Javascript Enlarge image

Source: Internet
Author: User

Core code is collected on the Internet (IE6, 7,8, Firefox/3.6.11 and tt4.8 are tested successfully ).

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT type = "text/JavaScript">
Function createpopup (){
VaR setelementstyles = function (element, styledict ){
VaR style = element. style;
For (VAR stylename in styledict) style [stylename] = styledict [stylename];
}
VaR ediv = Document. createelement ('div ');
Setelementstyles (ediv, {'position': 'absolute ', 'top': 0 + 'px', 'left': 0 + 'px ', 'width ': 0 + 'pxy', 'height': 0 + 'pxy', 'zindex': 1000, 'display': 'none', 'overflow': 'hidden '});
Ediv. Body = ediv;
VaR opened = false;
VaR setopened = function (B ){
Opened = B;
}
VaR getopened = function (){
Return opened;
}
VaR getcoordinates = function (oelement ){
VaR coordinates = {X: 0, Y: 0 };
While (oelement ){
Coordinates. x + = oelement. offsetleft;
Coordinates. Y + = oelement. offsettop;
Oelement = oelement. offsetparent;
}
Return coordinates;
}
Return {
Htmltxt :'',
Document: ediv,
Isopen: getopened (),
Isshow: false,
Hide: function (){
Setelementstyles (ediv, {'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height ': 0 + 'px ', 'display': 'none '});
Ediv. innerhtml = '';
This. isshow = false;
},
Show: function (IX, Iy, iwidth, iheight, oelement ){
If (! Getopened () {document. Body. appendchild (ediv); setopened (true );};
This.html TXT = ediv. innerhtml;
If (this. isshow) {This. Hide ();};
Ediv. innerhtml = this.html txt;
VaR coordinates = getcoordinates (oelement );
Ediv. style. Top = (IX + coordinates. X) + 'px ';
Ediv. style. Left = (Iy + coordinates. Y) + 'px ';
Ediv. style. width = iwidth + 'px ';
Ediv. style. Height = iheight + 'px ';
Ediv. style. Display = 'block ';
This. isshow = true;
}
}
}
VaR opopup; // controls the display of images
If (! Window. createpopup ){
Opopup = createpopup ();
}
Else {
Opopup = Window. createpopup ();
}
Function filloutimage (imgurl, eventtag ){
With (opopup.doc ument. Body ){
Style. backgroundcolor = "lightyellow ";
Style. Border = "solid black 1px ";
Innerhtml = " ";
}
VaR event = eventtag | window. event;
Opopup. Show (event. clientx + 80, event. clienty + 10,300,250); // the size of the form
}
</SCRIPT>

</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>

</Div>
<Div id = "divhere"> </div>
</Form>
</Body>
</Html>

 

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.