js放大镜放大图片效果
我们 js图片放大镜
body {
background: #222;
overflow: hidden;
left: 0;
top: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#screen span {
position:absolute;
overflow:hidden;
border:#FFF solid 1px;
background:#FFF;
}
#screen img{
position:absolute;
left:-32px;
top:-32px;
cursor: pointer;
}
#caption, #title{
color: #FFF;
font-family: georgia, 'times new roman', times, veronica, serif;
font-size: 1em;
text-align: center;
}
#caption b {
font-size: 2em;
}
0 && w Sx))
{
/* force window.event */
window.focus();
/* loop */
setTimeout("obj[" + o + "].zoom()", 16);
}
else
{
/* finished */
mv = false;
/* set final position */
if (s > 0)
{
l = ix * M + ix * Sx;
t = iy * M + iy * Sy;
w = Wi;
h = Hi;
}
else
{
l = x * M + x * Sx;
t = y * M + y * Sy;
w = Sx;
h = Sy;
}
}
/* html animation */
with(spa)
{
left = px(l);
top = px(t);
width = px(w);
height = px(h);
zIndex = Math.round(w);
}
}
}
this.click = function()
{
with(this)
{
img_center(o);
/* zooming logic */
if ( ! mv || cl)
{
if (s > 0)
{
if (cl || Math.abs(xm - xb) > Sx * .4 || Math.abs(ym - yb) > Sy * .4)
{
s = - 2;
mv = true;
zoom();
cap.innerHTML = txt;
}
}
else
{
if (cl || ob != o)
{
if (ob >= 0)
{
with(obj[ob])
{
s = - 2;
mv = true;
zoom();
}
}
ob = o;
s = 1;
xb = xm;
yb = ym;
mv = true;
zoom();
cap.innerHTML = txt;
}
}
}
}
}
/* hook up events */
img[o].onmouseover = img[o].onmousemove = img[o].onmouseout = new Function("cl=false;obj[" + o + "].click()");
img[o].onclick = new Function("cl=true;obj[" + o + "].click()");
img[o].onload = new Function("img_center(" + o + ")");
/* initial display */
this.zoom();
}
/* mouse */
document.onmousemove = function(e)
{
if ( ! e)
{
e = window.event;
}
xm = (e.x || e.clientX);
ym = (e.y || e.clientY);
}
/* init */
function load()
{
/* html elements */
scr = document.getElementById("screen");
spa = scr.getElementsByTagName("span");
img = scr.getElementsByTagName("img");
cap = document.getElementById("caption");
/* mouseover border */
document.getElementById("border").onmouseover = function()
{
cl = true;
if(ob >= 0 && obj[ob].s > 0) obj[ob].click();
ob = -1;
}
/* global variables */
W = parseInt(scr.style.width);
H = parseInt(scr.style.height);
M = W / Mg;
Sx = (W - (Nx - 1) * M) / Nx;
Sy = (H - (Ny - 1) * M) / Ny;
Wi = Tx * Sx + (Tx - 1) * M;
Hi = Ty * Sy + (Ty - 1) * M;
SP = M * Tx * SP;
wi = (Wi - Sx) / SP;
hi = (Hi - Sy) / SP;
/* create objects */
for (k = 0, i = 0; i
carefully weight the options
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]