@keyframes appear {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes appearFromTop {
0% {
opacity: 0;
transform: translateY(-500px);
border-radius: 50px;
}
30% {
opacity: 1;
transform: translateY(0);
}
50% {
border-radius: 10px;
}
100% {
opacity: 0;
transform: translateY(-500px);
border-radius: 50px;
}
}
.box {
width: 500px;
height: 60px;
background-color: black;
position: absolute;
top: 0;
bottom: 800px;
left: 0;
right: 0;
margin: auto;
transition: background-color 0.25s 0.25s ease-in-out;
}
.box--from-top {
animation: appearFromTop 5s 0.5s both;
}
我希望這個影片能在頁面上停留幾秒鐘然后消失。所以我的問題是:我該怎么做?我想我什么都試過了。影片延遲不起作用,影片播放狀態不起作用
uj5u.com熱心網友回復:
您可以在影片程序中添加“no-op”:即在影片時間軸的 10% 到 90% 之間使不透明度為 1。
對于 5 秒的長度,這意味著 5 秒的 80%(即 4 秒)元素保持完全不透明度,0.5 秒淡入和 0.5 秒淡出。
box{
animation: 5s linear 0s 1 normal fade-in-out;
opacity: 0;
}
@keyframes fade-in-out{
0% {opacity: 0}
10% {opacity: 1}
90% {opacity: 1}
100% {opacity: 0}
}
<box> Hello, world! </box>
uj5u.com熱心網友回復:
像這樣的東西?您可以制作較長的影片,并且僅在某些百分比值之間進行影片處理。
例如:一個 5 秒的影片,在 0-20% 之間發生淡入,在 80-100% 之間發生淡出,這意味著它淡入 1 秒,在螢屏上保持 3 秒,再次淡出 1 秒。
.box {
width: 500px;
height: 60px;
background-color: black;
position: absolute;
top: -60px;
left: 0;
margin: auto;
}
.box--from-top {
animation: inOut 5s;
}
@keyframes inOut {
0% {
transform: translateY(0);
opacity: 0;
}
20% {
transform: translateY(50px);
opacity: 1;
}
80% {
transform: translateY(50px);
opacity: 1;
}
100% {
transform: translateY(0);
opacity: 0;
}
}
<div class="box box--from-top"></div>
也可以有一個單獨的淡入淡出影片 CSS 影片與一點點 javascript 為你做的伎倆。這通常可以更靈活。
const box = document.querySelector('.box');
setTimeout(function(){
box.classList.remove('fadein');
box.classList.add('fadeout');
}, 5000);
.box {
width: 500px;
height: 60px;
background-color: black;
position: absolute;
top: 0;
left: 0;
margin: auto;
}
.fadein {
animation: fadein 1s;
}
.fadeout {
animation: fadeout 1s;
animation-fill-mode: forwards;
}
@keyframes fadein {
0% {
opacity: 0;
top: -60px;
}
100% {
top: 0;
opacity: 1;
}
}
@keyframes fadeout {
0% {
opacity: 1;
}
100% {
top: -60px;
opacity: 0;
}
}
<div class="box fadein"></div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/459668.html
上一篇:使用React,我怎樣才能讓模態出現影片,而不是已經在DOM中?
下一篇:為什么我的滑塊不能正常向后作業
