-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.html
282 lines (271 loc) · 11.7 KB
/
01.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./css/reset.css">
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<!-- 最外侧 -->
<div class="outer">
<!-- 尚品汇的头部区域 -->
<header>
<!-- 灰色区域 -->
<div class="header-outer">
<div class="header">
<div class="left">
<span>尚品汇欢迎您 请</span>
<a href=":;javaScript">登录</a>
<a href=":;javaScript">免费注册</a>
</div>
<div class="right">
<a href=":;javaScript">我的订单</a>
<a href=":;javaScript">我的购物车</a>
<a href=":;javaScript">我的尚品汇</a>
<a href=":;javaScript">尚品汇会员</a>
<a href=":;javaScript">企业采购</a>
<a href=":;javaScript">关注尚品汇</a>
<a href=":;javaScript">合作招聘</a>
<a href=":;javaScript">商家后台</a>
</div>
</div>
</div>
<!-- logo区域 -->
<div class="logo-outer">
<h1 class="left">
<img src="./images/Logo.png" alt="">
</h1>
<div class="right">
<input type="text">
<button>搜索</button>
</div>
</div>
</header>
<div class="allnav_outer">
<div class="allnav">
<h2>所有商品分类</h2>
<nav>
<a href="javascript:;">服装城</a>
<a href="javascript:;">美妆馆</a>
<a href="javascript:;">尚品汇超市</a>
<a href="javascript:;">全球购</a>
<a href="javascript:;">闪购</a>
<a href="javascript:;">团购</a>
<a href="javascript:;">有趣</a>
<a href="javascript:;">秒杀</a>
</nav>
</div>
</div>
<section class="con">
<div class="conPoint">
<a href="javascript:;">手机、数码、通讯手机</a>
<a href="javascript:;">Apple苹果</a>
<a>iphone 6S系类</a>
</div>
<div class="mainCon">
<div class="previewArea">
<div class="preview">
<!-- 小图区域 -->
<div class="smallArea">
<img src="./images/s1.png" alt="">
<!-- 蒙版区域 -->
<!-- <div class="mask"></div> -->
</div>
<!-- 大图区域 -->
<!-- <div class="bigArea">
<img src="./images/b1.png" alt="">
</div> -->
</div>
<div class="prescroll">
<p class="left"><</p>
<div class="listOut">
<ul class="list">
<!-- 动态加载图片资源 -->
</ul>
</div>
<p class="right">></p>
</div>
</div>
<div class="detailArea">
<div class="priceArea">
<h3 class="title">Apple iPhone 6s(A1700)64G玫瑰金色 移动通信电信4G手机</h3>
<p class="con">推荐选择下方[移动优惠购],手机套餐齐搞定,不用换号,每月还有花费返</p>
<div class="price">
<div class="priceDetail">
<p>价 格</p>
<p>¥ <span>5299</span> 元</p>
</div>
<div class="buy">
<p>促 销</p>
<p><span>加价购</span>满999.00另加20.00元,或满1999.00另加30.00元,或满2999.00另加40.00元,即可在购物车换购热销商品</p>
</div>
</div>
<div class="support">
<div class="supportDetail">
<p>支 持</p>
<p>以旧换新,闲置手机回收 4G套餐超值抢 礼品购</p>
</div>
<div class="address">
<p>配 送 至</p>
<p>广东省 深圳市 宝安区</p>
</div>
</div>
</div>
<div class="chooseInsert">
</div>
<div class="chooseArea">
<dl>
<dt>选择颜色</dt>
<dd>金色</dd>
<dd>银色</dd>
<dd>黑色</dd>
</dl>
<dl>
<dt>内存容量</dt>
<dd>16G</dd>
<dd>32G</dd>
<dd>64G</dd>
<dd>128G</dd>
</dl>
<dl>
<dt>选择版本</dt>
<dd>公开版</dd>
<dd>移动版</dd>
</dl>
<dl>
<dt>选择优惠</dt>
<dd>官方标配</dd>
<dd>移动优惠版</dd>
<dd>电信优惠版</dd>
</dl>
</div>
<div class="goodsNum">
<div class="num">
<input type="text" value="1">
<button class="plus">+</button>
<button class="mins">-</button>
</div>
<div class="addCart">加入购物车</div>
</div>
</div>
</div>
</section>
</div>
</body>
<script src="./js/data.js"></script>
<script>
window.addEventListener("DOMContentLoaded", function () {
var imgIndex = 0;
// 放大镜蒙版区域
magnify();
function magnify() {
var oSmallArea = document.querySelector('.smallArea');
var oPreview = document.querySelector('.preview');
oPreview.onmouseenter = function () {
var data = goodData.imgsrc;
// 创建蒙版区域
var oMask = document.createElement("div");
oMask.classList.add("mask");
oSmallArea.appendChild(oMask);
// 大图区域
var oBigArea = document.createElement("div");
oBigArea.classList.add("bigArea")
var oImg = new Image();
oImg.src = data[imgIndex].b;
oBigArea.appendChild(oImg);
oPreview.appendChild(oBigArea);
// 获取元素
oPreview.onmousemove = function (e) {
// 计算距离
var move = {
x: e.clientX - oSmallArea.getBoundingClientRect().left - oMask.offsetWidth / 2,
y: e.clientY - oSmallArea.getBoundingClientRect().top - oMask.offsetHeight / 2,
}
// 计算临界值
if (move.x >= oSmallArea.clientWidth - oMask.offsetWidth) {
move.x = oSmallArea.clientWidth - oMask.offsetWidth
} else if (move.x <= 0) {
move.x = 0
}
if (move.y >= oSmallArea.clientHeight - oMask.offsetHeight) {
move.y = oSmallArea.clientHeight - oMask.offsetHeight
} else if (move.y <= 0) {
move.y = 0
}
// 进行赋值
oMask.style.left = move.x + "px";
oMask.style.top = move.y + "px";
// 计算比例
var scale = (oSmallArea.clientWidth - oMask.offsetWidth) / (oBigArea.clientWidth - oImg.offsetHeight);
var bigMove = {
x: move.x / scale,
y: move.y / scale
}
//图片移动的距离
oImg.style.left = bigMove.x + "px";
oImg.style.top = bigMove.y + "px";
}
// 当鼠标离开时
oPreview.onmouseleave = function () {
oPreview.onmousemove = null;
oPreview.onmouseleave = null;
oSmallArea.removeChild(oMask);
oPreview.removeChild(oBigArea);
}
}
}
// 加载资源
loadData();
function loadData() {
var oList = document.querySelector('.listOut .list');
var data = goodData.imgsrc;
data.forEach((item, index) => {
var newLi = document.createElement("li");
var newImg = new Image();
newImg.src = item.s;
newLi.appendChild(newImg);
oList.appendChild(newLi)
})
}
// 点击左右键小图开始移动左右移动俩张
smallMove();
function smallMove() {
var oLeft = document.querySelector('.prescroll .left');
var oRight = document.querySelector('.prescroll .right');
var oLi = document.querySelectorAll('.listOut .list li');
var oListOut = document.querySelector('.listOut');
var oList = document.querySelector('.listOut .list');
// 这里计算可以移动的总距离要使用个数进行计算,使用list的宽度不准确
var allMove = (oLi.length - 5) * oLi[0].offsetWidth;
var everyMove = oLi[0].offsetWidth * 2;
oRight.onclick = function () {
if (allMove - oListOut.scrollLeft >= everyMove) {
oListOut.scrollLeft += everyMove;
console.log(oListOut.scrollLeft + "右键");
} else {
oListOut.scrollLeft = allMove;
console.log(oListOut.scrollLeft + "右键最后");
}
}
oLeft.onclick = function () {
oListOut.scrollLeft -= everyMove;
}
}
// 点击小图上面的放大镜区域跟着进行变化
clickSmall();
function clickSmall() {
var oImg = document.querySelectorAll('.listOut .list li img');
var oSmallArea = document.querySelector('.preview .smallArea img');
var data = goodData.imgsrc;
oImg.forEach((item, index) => {
item.onclick = function () {
oSmallArea.src = data[index].b;
imgIndex = index;
}
})
}
})
</script>
</html>