forked from dev-zuo/nice-func
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch-phone-color-when-scroll.html
254 lines (245 loc) · 7.1 KB
/
switch-phone-color-when-scroll.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="/lib/gsap.min.js"></script>
<script src="/lib/ScrollTrigger.min.js"></script>
<style>
body {
height: 4500px;
}
.containerX {
position: absolute;
width: 100%;
bottom: 0;
height: 100vh;
}
/* transform: translate(695px, 575px) scale(2.5, 2.5); */
/* 层级3: 图片 */
.umx-img {
margin: 0; /* 去除默认 margin */
background-size: 461px 605px;
background-position: center;
background-repeat: no-repeat;
width: 461px;
height: 605px;
}
/* 层级2:包裹高度 100vh */
.f-box {
position: absolute;
bottom: 0;
height: 100vh;
min-height: 750px;
display: flex;
align-items: center;
}
/* 层级1:滚动时,改变高度百分比实现颜色切换 */
.f-mask {
position: absolute;
width: 100%;
height: 0;
bottom: 0;
}
/* 层级0: 固定图片在中间 */
.umx-figure {
width: 461px;
margin: 0;
height: 100vh;
min-height: 750px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 99;
}
.umx-img.umx-f1 {
background-image: url(./images/iqooneo7-color-img1-md.png);
}
.umx-img.umx-f2 {
background-image: url(./images/iqooneo7-color-img2-md.png);
}
.umx-img.umx-f3 {
background-image: url(./images/iqooneo7-color-img3-md.png);
}
.color-bg {
position: absolute;
width: 100%;
height: 0;
bottom: 0;
overflow: hidden;
}
.color-bg.orange-bg {
background-color: #ffeee8;
}
.color-bg.blue-bg {
background-color: #effbfc;
}
.color-bg.black-bg {
background-color: #dae1e7;
}
.mask-box {
position: absolute;
width: 50%;
height: 100vh;
min-height: 750px;
left: 0;
bottom: 0;
overflow: hidden;
}
.color-txt {
width: 230px;
height: 100vh;
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
display: flex;
align-items: flex-start;
flex-direction: column;
justify-content: center;
font-family: Arial, Helvetica, sans-serif;
}
.color-txt strong {
font-size: 84px;
}
.color-txt p {
font-size: 34px;
}
.orange-bg strong {
color: #f6683a;
}
.orange-bg p {
color: #fdbfab;
}
.blue-bg strong {
color: #38bec1;
}
.blue-bg p {
color: #a5e2e4;
}
.black-bg strong {
color: #182130;
}
.black-bg p {
color: #94aab8;
}
</style>
</head>
<body>
<div>
<div class="containerX">
<!-- 3张手机图片叠加 -->
<div class="umx-figure">
<div class="f-mask umx-orange" style="overflow: hidden; height: 100%">
<div class="f-box">
<figure
class="umx-img umx-f1"
style="transform: translate(0px, 0px)"
></figure>
</div>
</div>
<div
class="f-mask umx-blue"
style="display: block; overflow: hidden; height: 0%"
>
<div class="f-box">
<figure class="umx-img umx-f2"></figure>
</div>
</div>
<div
class="f-mask umx-black"
style="display: block; overflow: hidden; height: 0%"
>
<div class="f-box">
<figure class="umx-img umx-f3"></figure>
</div>
</div>
</div>
<!-- 三个背景叠加 -->
<div class="mask-box">
<!-- -->
<div class="color-bg orange-bg active" style="height: 100%">
<div class="color-txt" style="transform: translate(-50%, 0%)">
<strong>橙</strong>
<p>大胆和前卫<br />的姿态</p>
</div>
</div>
<!-- style="height: 7.369%;" -->
<div class="color-bg blue-bg" style="height: 0%">
<div class="color-txt" style="transform: translate(-50%, 0%)">
<strong>蓝</strong>
<p>挑战和突破<br />的精神</p>
</div>
</div>
<div class="color-bg black-bg" style="height: 0px">
<div class="color-txt" style="transform: translate(-50%, 0%)">
<strong>黑</strong>
<p>简洁跳动<br />的语言</p>
</div>
</div>
</div>
</div>
</div>
<script>
gsap.registerPlugin(ScrollTrigger);
// pin 为 true 时,触发动画的元素 在滚动时可以保持不向上滚动,让整个容器在滚动时固定
gsap.to(".containerX", {
opacity: 1,
scrollTrigger: {
trigger: ".containerX",
start: "top top",
end: "240%", // 向下滚动 240% 距离时结束
scrub: true, // 表示动画可以重复执行改成false表示只执行一次
// markers: true, // 绘制开始位置和结束位置的线条
pin: true, // 动画执行期间,页面不进行滚动,动画执行结束后
},
});
// 第一次动画,橙/蓝颜色切换
// 蓝色手机覆盖橙色手机,触发实际,.umx-blue 进入 viewport
gsap.to(".umx-blue", {
height: "100%",
ease: "expo-out",
scrollTrigger: {
trigger: ".umx-blue",
scrub: true,
// markers: true,
},
});
gsap.to(".blue-bg", {
height: "100%",
ease: "expo-out",
scrollTrigger: {
trigger: ".blue-bg",
scrub: true,
// markers: true,
},
});
// 第二次动画,黑/蓝手机切换
// 等 blue 蓝色手机动画结束后,其 top 到达 viewport 视窗顶部时,触发下次动画
gsap.to(".umx-black", {
height: "100%",
scrollTrigger: {
trigger: ".blue-bg",
start: "top top",
end: "+1200",
scrub: true,
// markers: true,
},
});
gsap.to(".black-bg", {
height: "100%",
scrollTrigger: {
trigger: ".blue-bg",
start: "top top",
end: "+1200",
scrub: true,
// markers: true,
},
});
// gsap.fromTo(".phone-wrap img", { x: 695,y: 575, scale: 2.5,}, {x: 0, yy: 0, scale: 1});
</script>
</body>
</html>