<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = iso-8859-1"/>
<Title> image magnifiers </title>
<Style>
# Zoomdiv {
Position: absolute;
Background: # ffffff;
Border: 1px solid # CCCCCC;
Display: none;
Text-align: center;
Overflow: hidden;
}
# Zoomup {
Position: absolute;
Background: # c0c0c0;
Display: none;
Filter: alpha (opacity = 50 );
Opacity:. 5;
Cursor: move;
}
. Zoom {
Position: relative;
}
</Style>
</Head>
<Body>
<Div style = "position: absolute; Border: 1px solid # c0c0c0; left: 400px; "> </div>
</Body>
</Html>
<SCRIPT>
VaR zoom = function (o ){
VaR d = Document, DB = Document. Body, timgs = D. getelementsbytagname ('img '), ie =! + '\ V1', isstrict = D. compatmode = "css1compat ",
Opt = {
Width: 200,
Height: 200,
Offset: 20,
Float: 'riyun ',
Min width: 100
},
DIV = D. createelement ('div '), divup = D. createelement ('div '),
Getxy = function (EL ){
VaR r = {T: 0, L: 0 },
UA = navigator. useragent. tolowercase (),
Add = function (T, L) {R. L + = L, R. T + = t },
P = el;
If (el & el! = Db ){
If (el. getBoundingClientRect ){
Var B = el. getBoundingClientRect ();
Add (B. top + Math.max(d.body.scrollTop,d.doc umentElement. scrollTop ),
B .left;math.max(d.body.scrollleft,d.doc umentElement. scrollLeft ));
IsStrict? Add(-d.documentElement.clientTop,-d.doc umentElement. clientLeft): add (-1,-1)
} Else {
Var dv = d. defaultView;
While (p ){
Add (p. offsetTop, p. offsetLeft );
P = p. offsetParent;
}
P = el. parentNode;
While (p & p! = Db ){
Add (-p. scrollTop,-p. scrollLeft );
P = p. parentNode;
}
}
}
Return r;
},
Extend = function (t, s ){
For (var p in s ){
T [p] = s [p];
};
};
Div. id = 'zoomdiv ', divup. id = 'zoomup ';
Div. innerHTML = ' ';
Db. appendChild (div );
Extend (opt, o );
Function leave (){
Div. style. display = divup. style. display = 'none ';
Db. onmousemove = null;
};
For (var I = 0, ci; ci = timgs [I ++];) {
If (ci. className = 'zoom '){
Ci. onmouseover = function (e ){
This. parentNode. appendChild (divup );
Var bimg = d. getElementById ('bigimg '), bwidth, bheight, sx, sy,
Width = this. offsetWidth, height = this. height, top = getXY (this). t, left = getXY (this). l, tWidth, tLeft, sWidth;
Bimg. onload = function (){
Div. style. display = 'block ';
Bwidth = bimg. width, bheight = bimg. height,
Sx = bwidth/width, sy = bheight/height;
TLeft = opt. float = 'riyun '? Opt. offset + width + left: left-opt.offset-width * opt. width * sx,
SWidth = window. innerWidth | (isStrict? D.doc umentElement. clientWidth: db. clientWidth );
If (tLeft + opt. width + 5> sWidth ){
TWidth = sWidth-5-tLeft;
TWidth <opt. minWidth & (tLeft = left-opt.offset-opt.width, tWidth = 0 );
};
Extend (div. style ,{
Left: tLeft + 'px ',
Top: top + 'px ',
Width :( tWidth | opt. width) + 'px ',
Height: opt. height + 'px'
});
Extend (divup. style ,{
Width :( twidth | opt. width)/SX + 'px ',
Height: OPT. Height/SY + 'px ',
Display: 'block'
})
DB. onmousemove = function (e ){
VaR E = E | event, x = E. pagex | (e.clientx((d.doc umentelement. scrollleft | dB. scrollleft), Y = E. pagey | (e.clienty((d.doc umentelement. scrolltop | dB. scrolltop )),
Scrolly = y-divup. offsetHeight/2-top,
Scrollx = x-divup. offsetWidth/2-left;
Scrolly = y-divup. offsetHeight/2 <top? 0: y + divup. offsetHeight/2> height + top? Height-divup. offsetHeight: scrolly;
Scrollx = x-divup. offsetWidth/2 <left? 0: x + divup. offsetWidth/2> width + left? Width-divup. offsetWidth: scrollx;
Div. scrollTop = scrolly * sy;
Div. scrollLeft = scrollx * sx;
Extend (divup. style, {top: scrolly + 'px', left: scrollx + 'px '});
}
}
Bimg. src = this. getAttribute ('Big ');
};
Ci. parentNode [ie? 'Onmouseleave ': 'onmouseout'] = ie? Leave: function (e ){
! (This = e. relatedTarget | (this. contains? This. contains (e. relatedTarget): this. compareDocumentPosition (e. relatedTarget) = 20) & leave ();
}
}
};
}
Zoom ({width: 300, height: 300 });
</Script>