Skip to content

Commit ac8fcbd

Browse files
author
linyisonger
committed
没什么可以优化的空间
1 parent 33cfa34 commit ac8fcbd

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

102.镜面滑屏.html

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030

3131

32+
33+
3234
.container {
3335
position: relative;
3436
display: flex;
@@ -69,13 +71,11 @@
6971

7072
.v2 {
7173
clip-path: polygon(-15% 0%, 0% 0%, -10% 100%, -25% 100%);
72-
animation-name: v2LeftToRight;
73-
animation-duration: 3s;
74-
animation-timing-function: ease-in;
75-
animation-iteration-count: infinite;
7674
}
7775

7876

77+
78+
7979
video {
8080
width: 100%;
8181
height: 100%;
@@ -103,68 +103,67 @@
103103
height: 100%;
104104
background: linear-gradient(-80deg, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 1) 35%, rgba(0, 0, 0, 1) 65%, rgba(0, 0, 0, 0) 75%);
105105
transform: scaleX(1.1);
106-
animation-name: v2ShadowLeftToRight;
107-
animation-duration: 3s;
108-
animation-timing-function: ease-in;
109-
animation-iteration-count: infinite;
110106
}
111107

112108
.l2 {
113109
position: absolute;
114110
width: 100%;
115111
height: 100%;
116-
transition: opacity .5s ease;
117112
}
118113

119-
.hide {
120-
opacity: 0;
114+
115+
.v2.playing {
116+
animation-name: v2LeftToRight;
117+
animation-duration: 3s;
118+
animation-timing-function: ease-in;
119+
animation-iteration-count: infinite;
120+
}
121+
122+
.v2-shadow.playing {
123+
animation-name: v2ShadowLeftToRight;
124+
animation-duration: 3s;
125+
animation-timing-function: ease-in;
126+
animation-iteration-count: infinite;
121127
}
122128
</style>
123129
</head>
124130

125131
<body>
126132
<div class="container">
127133
<div class="v1">
128-
<video muted autoplay class="l1">
134+
<video muted class="l1">
129135
<source src="./assets/effects-video/frxxz-p1.mp4">
130-
</video>
131-
<video muted class="l2 hide">
132136
<source src="./assets/effects-video/frxxz-p2.mp4">
133137
</video>
134138
</div>
135-
<div class="v2-shadow"></div>
136-
<div class="v2">
137-
<video muted autoplay class="l1">
139+
<div class="v2-shadow playing"></div>
140+
<div class="v2 playing">
141+
<video muted class="l1">
138142
<source src="./assets/effects-video/frxxz-p1.mp4">
139-
</video>
140-
<video muted class="l2 hide">
141143
<source src="./assets/effects-video/frxxz-p2.mp4">
142144
</video>
143145
</div>
144146
</div>
145147

146148
<script type="module">
147-
let v1VideoDOM = document.querySelectorAll('.v1 video')
148-
let v2VideoDOM = document.querySelectorAll('.v2 video')
149+
let v2DOM = document.querySelector(".v2")
149150
let v2ShadowDOM = document.querySelector(".v2-shadow")
150-
v1VideoDOM.item(0).addEventListener("ended", () => {
151-
v1VideoDOM.item(1).classList.remove('hide')
152-
v1VideoDOM.item(1).play()
153-
})
154-
v2VideoDOM.item(0).addEventListener("ended", () => {
155-
v2VideoDOM.item(1).classList.remove('hide')
156-
v2VideoDOM.item(1).play()
157-
})
158-
159-
v1VideoDOM.item(1).addEventListener("ended", () => {
160-
v1VideoDOM.item(1).classList.add('hide')
161-
v1VideoDOM.item(0).play()
162-
})
163-
v2VideoDOM.item(1).addEventListener("ended", () => {
164-
v2VideoDOM.item(1).classList.add('hide')
165-
v2VideoDOM.item(0).play()
166-
})
167151

152+
let videosDOM = document.querySelectorAll('video')
153+
let videoMainDOM = videosDOM.item(0);
154+
let videoSubDOM = videosDOM.item(1)
155+
156+
let sources = videoMainDOM.querySelectorAll('source')
157+
let currentPlayIndex = 0;
158+
function playNextVideo() {
159+
currentPlayIndex++;
160+
videoMainDOM.src = videoSubDOM.src = sources[currentPlayIndex % sources.length].src
161+
videoMainDOM.play()
162+
videoSubDOM.play()
163+
}
164+
videoMainDOM.addEventListener('ended', playNextVideo)
165+
videoMainDOM.play();
166+
videoSubDOM.play()
168167

169168
function updateV2Shadow() {
170169
const opposite = document.body.clientWidth * .1;

0 commit comments

Comments
 (0)