-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoomUp.html
102 lines (102 loc) · 2.07 KB
/
ZoomUp.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
* {margin: 0,padding: 0;}
img {
vertical-align: top;
}
.box {
position: relative;
width: 350px;
height: 350px;
margin: 100px;
border: 1px solid #ccc;
}
.big {
position: absolute;
top: 0;
left: 360px;
width: 450px;
height: 450px;
border: 1px solid #ccc;
overflow: hidden;
}
.big img {
position: absolute;
top: 0;
left: 0;
}
.small {
position: relative;
}
.mask {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
display: none;
background: rgba(0,100,100,0.3);
cursor: move;
}
</style>
</head>
<body>
<div class="box" id="fdj">
<div class="big">
<img src="images/0001.jpg">
</div>
<div class="small">
<img src="images/001.jpg">
<div class="mask"></div>
</div>
</div>
</body>
<script type="text/javascript">
var fdj = document.getElementById("fdj");
var big = fdj.children[0];
var small = fdj.children[1];
var mask = small.children[1];
var bigImage = big.children[0];
small.onmouseover = function(){
mask.style.display = "block";
big.style.display = "block";
}
small.onmouseout = function(){
mask.style.display = "none";
big.style.display = "none";
}
//鼠标在small内移动
var x = 0;
var y = 0;
small.onmousemove = function(event){
var event = event || window.event;
x = event.clientX - this.offsetParent.offsetLeft - mask.offsetWidth/2;
y = event.clientY - this.offsetParent.offsetTop - mask.offsetHeight/2;
//定界
if(x < 0)
{
x = 0;
}
else if(x > small.offsetWidth - mask.offsetWidth)
{
x = small.offsetWidth - mask.offsetWidth;
}
if(y < 0)
{
y = 0;
}
else if(y > small.offsetHeight - mask.offsetHeight)
{
y = small.offsetHeight - mask.offsetHeight;
}
mask.style.left = x + "px";
mask.style.top = y + "px";
bigImage.style.left = -x * big.offsetWidth/small.offsetWidth + "px";
bigImage.style.top = -y * big.offsetHeight/small.offsetHeight + "px";
}
</script>
</html>