-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path放大镜.html
185 lines (179 loc) · 4.91 KB
/
放大镜.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
overflow: hidden;
}
.left {
float: left;
width: 450px;
height: 450px;
background: url(img/back.jpg) no-repeat;
position: relative;
background-size: 100%;
border: 1px solid green;
}
.mask {
width: 200px;
height: 200px;
position: absolute;
background: yellow;
opacity: 0.5;
display: none;
}
.right {
position: absolute;
left: 452px;
float: left;
width: 500px;
height: 500px;
border: 1px solid #111;
background: url(img/back.jpg) no-repeat;
background-size: 1000px 1000px;
display: none;
/* background-position: ; */
}
.con{
overflow: hidden;
}
.l-de,.r-de{
float: left;
width: 30px;
height: 70px;
color: #666;
font-weight: bold;
font-family: '宋体';
font-size: 30px;
cursor: pointer;
line-height: 80px;
text-align: center;
}
.tab {
width: 392px;
height: 70px;
/* background-color: #ccc; */
overflow: hidden;
float: left;
}
.tab img{
width: 52px;
margin-left: 15px;
height: 66px;
border: 2px solid #fff;
}
.bottom{
margin-top: 20px;
overflow: hidden;
}
.tab-con{
width: 784px;
}
</style>
</head>
<body>
<div class="con">
<div class="left">
<div class="mask"></div>
</div>
<div class="right"></div>
</div>
<div class="bottom">
<p class="l-de"><</p>
<div class="tab">
<div class="tab-con">
<img src="img/back.jpg" alt="" />
<img src="img/back2.jpg" alt="" />
<img src="img/back3.jpg" alt="" />
<img src="img/back4.jpg" alt="" />
<img src="img/back5.jpg" alt="" />
<img src="img/back6.jpg" alt="" />
<img src="img/back7.jpg" alt="" />
<img src="img/back8.jpg" alt="" />
<img src="img/back9.jpg" alt="" />
<img src="img/back10.jpg" alt="" />
</div>
</div>
<p class="r-de">></p>
</div>
<script>
var mask = document.querySelector(".mask");
var left = document.querySelector(".left");
var right = document.querySelector(".right");
left.onmousemove = function (e) {
right.style.display = "block";
mask.style.display = "block";
var e = e || event;
var l = e.clientX - 100;
var t = e.clientY - 100;
if (l <= 0) {
l = 0;
} else if (l >= 250) {
l = 250;
}
if (t <= 0) {
t = 0;
} else if (t >= 250) {
t = 250;
}
mask.style.left = l + "px";
mask.style.top = t + "px";
var scaleL = l / (450 - 200);
var scaleT = t / (450 - 200);
right.style.backgroundPositionX = -500 * scaleL + "px";
right.style.backgroundPositionY = -500 * scaleT + "px";
};
left.onmouseleave = function (e) {
mask.style.display = "none";
right.style.display = "none";
};
var imgs=document.querySelectorAll(".tab img");
var ld=document.querySelector(".l-de");
var rd=document.querySelector(".r-de");
var tab=document.querySelector(".tab");
for(var i=0;i<imgs.length;i++){
imgs[i].index=i;
imgs[i].onmouseenter=function(){
for(var i=0;i<imgs.length;i++){
imgs[i].style.border="2px solid #fff";
}
imgs[this.index].style.border="2px solid red";
var num=imgs[this.index].src.indexOf("img");
left.style.background="url("+imgs[this.index].src.slice(num)+") no-repeat";
right.style.background="url("+imgs[this.index].src.slice(num)+") no-repeat";
right.style.backgroundSize="1000px 1000px";
}
imgs[i].onmouseleave=function(){
// imgs[this.index].style.border="2px solid #fff";
}
}
ld.onclick=function(){
var timer= setInterval(function(){
if(tab.scrollLeft>0){
tab.scrollLeft-=5;
}else{
tab.scrollLeft=0;
clearInterval(timer)
}
},1)
}
rd.onclick=function(){
var timer2= setInterval(function(){
if(tab.scrollLeft<322){
tab.scrollLeft+=5;
}else{
tab.scrollLeft=322;
clearInterval(timer2)
}
},1)
}
</script>
</body>
</html>