-
Notifications
You must be signed in to change notification settings - Fork 6
/
049-放大镜.html
151 lines (143 loc) · 3 KB
/
049-放大镜.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
* {
margin: 0px;
padding: 0;
border: none;
}
img {
display: block;
}
#div1 {
width: 200px;
height: 200px;
padding: 5px;
border: 1px solid #ccc;
position: relative; margin:20px;
}
#div1 .small_pic {
width: 200px;
height: 200px;
background: #eee;
position: relative;
}
#div1 .float_layer {
width: 50px;
height: 50px;
border: 1px solid #000;
background: #fff;
filter: alpha(opacity: 30);
opacity: 0.3;
position: absolute;
top: 0;
left: 0;
display: none;
}
#div1 .mark {
width: 100%;
height: 100%;
position: absolute;
z-index: 2;
left: 0px;
top: 0px;
background: red;
filter:alpha(opacity:0);
opacity: 0;
}
#div1 .big_pic {
position: absolute;
top: -1px;
left: 215px;
width: 250px;
height: 250px;
overflow: hidden;
border: 2px solid #CCC;
display: none;
}
#div1 .big_pic img {
position: absolute;
top: -30px;
left: -80px;
}
</style>
<script>
function getClass(aParent,sClass)
{
var aEl = aParent.getElementsByTagName("*");
var ArrClass = [];
for(var i = 0; i < aEl.length; i++)
{
if(aEl[i].className == sClass)
{
ArrClass.push(aEl[i]);
}
}
return ArrClass;
}
window.onload = function()
{
var oDiv1 = document.getElementById("div1");
var oSmallPic = getClass(oDiv1, "small_pic")[0];
var oMark = getClass(oDiv1, "mark")[0];
var oFlayer = getClass(oDiv1, "float_layer")[0];
var oBigPic = getClass(oDiv1, "big_pic")[0];
var aImg = oBigPic.getElementsByTagName("img")[0];
oMark.onmouseover = function()
{
oFlayer.style.display = "block";
oBigPic.style.display = "block";
}
oMark.onmouseout = function()
{
oFlayer.style.display = "none";
oBigPic.style.display = "none";
}
oMark.onmousemove = function(ev)
{
var oEvent = ev || event;
var l = oEvent.clientX - oDiv1.offsetLeft - oSmallPic.offsetLeft - oFlayer.offsetWidth / 2;
var t = oEvent.clientY - oDiv1.offsetTop - oSmallPic.offsetLeft - oFlayer.offsetHeight / 2;
if(l < 0)
{
l = 0;
}
else if(l > oMark.offsetWidth - oFlayer.offsetWidth)
{
l = oMark.offsetWidth - oFlayer.offsetWidth;
}
if(t < 0)
{
t = 0;
}
else if(t > oMark.offsetHeight - oFlayer.offsetHeight)
{
t = oMark.offsetHeight - oFlayer.offsetHeight;
}
oFlayer.style.left = l + "px";
oFlayer.style.top = t + "px";
var percenterX = l / (oMark.offsetWidth - oFlayer.offsetWidth);
var percenterY = t / (oMark.offsetHeight - oFlayer.offsetHeight);
aImg.style.left = -percenterX * (aImg.offsetWidth - oBigPic.offsetWidth) + "px";
aImg.style.top = -percenterY * (aImg.offsetHeight - oBigPic.offsetHeight) + "px";
document.title = percenterX + ":" + percenterY;
}
}
</script>
</head>
<body>
<div id="div1">
<div class="small_pic">
<span class="mark"></span>
<span class="float_layer"></span>
<img src="049_img/small.png" />
</div>
<div class="big_pic">
<img src="049_img/big.png" />
</div>
</div>
</body>
</html>