我發現了一個出色的 CSS 影片,它在我正在處理的選單上看起來很棒。影片首先顯示一個 div 中的文本,幾秒鐘后顯示另一個 div 中的文本。再過幾秒鐘,兩個div中的文字就消失了。然后影片在重復。
我正在嘗試使用類創建兩個 div(以便可以使用 javascript 函式呼叫它們)。第一個 div 應該運行顯示兩個文本的影片部分。另一個 div 是兩個文本消失的影片。這兩個影片應該只運行一次。如何才能做到這一點?
代碼筆:https ://codepen.io/Atise/pen/YzQorxw
<div class="PrSidenav">
<div class="animation_container">
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
</div>
<div class="animation_container">
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
</div>
<div class="animation_container">
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
</div>
<div class="animation_container">
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
</div>
<div class="animation_container">
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
</div>
<div class="animation_container">
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
</div>
</div>
<style>
body {
background: white;
color: #555;
font-family: "Roboto";
font-weight: 300;
font-size: 32px;
padding-top: 40vh;
height: 100vh;
overflow: hidden;
}
.theSidenav {
width: 20vw !important;
}
.animation_container {
width: 14vw;
display: grid;
grid-template-columns: 16vw 10vw;
grid-gap: 10px;
}
.first_animation {
padding-right: 0;
margin-right: 0;
}
.first_animation,
.second_animation {
overflow: hidden;
/* white-space:nowrap; */
}
.first_animation {
animation: showup 7s forwards;
}
.second_animation {
width: 0px;
animation: reveal 7s forwards;
}
.second_animation span {
margin-left: -355px;
animation: slidein 7s forwards;
}
@keyframes showup {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 1;
}
}
@keyframes slidein {
0% {
margin-left: -800px;
}
20% {
margin-left: -800px;
}
35% {
margin-left: 0px;
}
100% {
margin-left: 0px;
}
}
@keyframes reveal {
0% {
opacity: 1;
width: 0px;
}
20% {
opacity: 1;
width: 0px;
}
30% {
width: 355px;
}
80% {
opacity: 1;
}
100% {
opacity: 1;
width: 355px;
}
}
p {
font-size: 12px;
color: #999;
margin-top: 200px;
}
</style>
uj5u.com熱心網友回復:
將無限更改為 1,影片將只運行一次
uj5u.com熱心網友回復:
我自己解決了,經過一些反復試驗!
https://codepen.io/Atise/pen/YzQorxw
HTML
<div class="first_animation">First part of the menu</div>
<div class="second_animation">
<span>Second part of the menu</span>
</div>
CSS
@import url("https://fonts.googleapis.com/css?family=Roboto:300");
body {
background: white;
color: #555;
font-family: "Roboto";
font-weight: 300;
font-size: 32px;
padding-top: 40vh;
height: 100vh;
overflow: hidden;
}
.thePrSidenav {
width: 20vw !important;
}
.animation_container {
width: 14vw;
display: grid;
grid-template-columns: 16vw 10vw;
grid-gap: 10px;
}
.first_animation {
padding-right: 0;
margin-right: 0;
}
.first_animation,
.second_animation {
overflow: hidden;
/* white-space:nowrap; */
}
.first_animation {
animation: showup 7s forwards;
}
.second_animation {
width: 0px;
animation: reveal 7s forwards;
}
.second_animation span {
margin-left: -355px;
animation: slidein 7s forwards;
}
@keyframes showup {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 1;
}
}
@keyframes slidein {
0% {
margin-left: -800px;
}
20% {
margin-left: -800px;
}
35% {
margin-left: 0px;
}
100% {
margin-left: 0px;
}
}
@keyframes reveal {
0% {
opacity: 1;
width: 0px;
}
20% {
opacity: 1;
width: 0px;
}
30% {
width: 355px;
}
80% {
opacity: 1;
}
100% {
opacity: 1;
width: 355px;
}
}
p {
font-size: 12px;
color: #999;
margin-top: 200px;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/324370.html
