-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtantan.slide.html
200 lines (187 loc) · 6.08 KB
/
tantan.slide.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta name="renderer" content="webkit">
<title>仿探探左滑右滑</title>
<meta name="description" content="首页描述"/>
<meta name="keywords" content="首页关键词"/>
<meta name="author" content="Web Layout:amu"/>
<meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no"/>
<link href="https://daneden.github.io/animate.css/animate.min.css" rel="stylesheet">
<style>
html{
height: 100%;
}
body{
max-width: 1000px;
margin: 0 auto;
padding: 0;
height: 100%;
overflow: hidden;
background: #f1f3f4;
}
h1{text-align: center;margin: 0;padding: 20px;}
h2{text-align: center;}
img{
width:100%;
height:330px;
background:#eee;
display: block;
}
.base-wrap{
width: 100%;
height: 100%;
margin: 0 auto;
}
.base-wrap ul{
position: relative;
list-style: none;
margin: 0;
padding: 30px;
box-sizing: border-box;
height: 100%;
}
.swiper-item{
position: absolute;
background: #fff;
width: 80%;
left: 10%;
box-shadow: 0 2px 10px rgba(0,0,0,.3);
text-align: center;
height: 480px;
border-radius: 10px;
overflow: hidden;
animation-duration:0.8s;
}
.swiper-item:nth-child(1){
z-index: 10;
top: 10px;
transform: scale(1);
}
.swiper-item:nth-child(2){
z-index: 9;
top: 32px;
transform: scale(0.93);
}
.swiper-item:nth-child(3){
z-index: 8;
top: 53px;
transform: scale(0.86);
}
.swiper-item:nth-child(4){
z-index: 7;
top: 74px;
transform: scale(0.79);
}
button{
background: coral;
color: #fff;
border: none;
padding: 10px 30px;
border-radius: 4px;
}
.swiper-item p{margin: 0;padding: 10px;}
.swiper-item p:nth-child(3){
font-size: 14px;
color: #666;
}
.swiper-item p:last-child{
padding-bottom: 23px;
}
</style>
</head>
<body>
<!-- <h1>左滑右滑</h1> -->
<h2>← ☜ ☞→</h2>
<div class="base-wrap">
<ul id="touchlayer">
<li class="swiper-item">
<img src="assets/images/001.jpg" alt="111">
<p>美女 A</p>
<p>学历:研究生 职位:算法工程师</p>
<p><button>+ 收藏</button></p>
</li>
<li class="swiper-item">
<img src="assets/images/002.jpg" alt="222">
<p>美女 B</p>
<p>学历:研究生 职位:算法工程师</p>
<p><button>+ 收藏</button></p>
</li>
<li class="swiper-item">
<img src="assets/images/003.jpg" alt="333">
<p>美女 C</p>
<p>学历:研究生 职位:算法工程师</p>
<p><button>+ 收藏</button></p>
</li>
<li class="swiper-item">
<img src="assets/images/004.jpg" alt="444">
<p>美女 D</p>
<p>学历:研究生 职位:算法工程师</p>
<p><button>+ 收藏</button></p>
</li>
</ul>
</div>
<script>
let touchEl = document.getElementById('touchlayer');
let pos={
startX:0,
startY:0
}
touchEl.ontouchstart = (ev)=>{
//console.log(ev.type,ev)
ev.stopPropagation();//禁用浏览器默认滑动
let target = ev.srcElement || ev.target;
let touchPoint = ev.touches[0]
pos.startX = touchPoint.pageX
pos.startY = touchPoint.pageY
}
touchEl.ontouchmove=(ev)=>{
ev.stopPropagation();//禁用浏览器默认滑动
ev.stopImmediatePropagation();//阻止事件捕获
let target = ev.srcElement || ev.target;
let touchPoint = ev.touches[0]
moveX = touchPoint.pageX-pos.startX
moveY = touchPoint.pageY-pos.startY;
if(target.classList.contains('swiper-item')){
target.style['transform'] = 'translate('+moveX+'px,'+moveY+'px)'
}else if(target.parentNode.classList.contains('swiper-item')){
target.parentNode.style['transform'] = 'translate('+moveX+'px,'+moveY+'px)'
}
}
touchEl.ontouchend = (ev)=> {
let target = ev.srcElement || ev.target;
let touchPoint = ev.changedTouches[0];
let distance = 50
distanceX = touchPoint.pageX-pos.startX
distanceY = touchPoint.pageY-pos.startY;
if(target.parentNode.classList.contains('swiper-item')){
console.log(distanceX,distanceX < 0,Math.abs(distanceX) > distance)
if(distanceX < 0 && Math.abs(distanceX) > distance){
console.log('左滑')
target.parentNode.classList.add('fadeOutLeftBig');
}else if(distanceX > distance){
console.log('右滑')
target.parentNode.classList.add('fadeOutRightBig');
}else{
console.log('回位')
target.parentNode.style['transform'] = 'translate('+0+'px,'+0+'px)'
return false
}
setTimeout(()=>{
//console.log('删除')
target.parentNode.remove();
let flag = document.createDocumentFragment();
let li = document.createElement('li');
li.setAttribute('class','swiper-item')
li.innerHTML ='<img src="assets/images/001.jpg"><p>SenseTime</p><p>学历:研究生 职位:算法工程师</p><p><button>+ 收藏</button></p>';
flag.appendChild(li);
touchEl.appendChild(flag)
},365)
}
}
</script>
</body>
</html>