英文:
How do I delay an element?
问题
我有这段CSS代码,但按钮完全消失了。如何让它在5秒后出现?
div#button-y4sCSuA9ms {
background-image: linear-gradient(170deg, #ffe259, #ffa751) !important;
box-shadow: 0 16px 32px 0 rgb(128 99 66 / 25%) !important;
color: rgba(0, 0, 0, 0.95) !important;
opacity: 0;
animation: fadeIn 1s;
animation-delay: 5s;
animation-fill-mode: forwards;
pointer-events: none;
}
英文:
I have this CSS code but the botton completely dissapears. How do I get it to appear after 5 seconds?
div#button-y4sCSuA9ms {
background-image: linear-gradient(170deg, #ffe259, #ffa751) !important;
box-shadow: 0 16px 32px 0 rgb(128 99 66 / 25%) !important;
color: rgba(0, 0, 0, 0.95) !important;
opacity: 0;
animation: fadeIn 1s;
animation-delay: 5s;
animation-fill-mode: forwards;
pointer-events: none;
}
答案1
得分: 0
也许你只是忘记为fadeIn
添加关键帧。
看下面的代码片段,它将在2秒后淡入按钮(如果要减少等待时间,可以将它调整回5秒):
div#button-y4sCSuA9ms {
background-image: linear-gradient(170deg, #ffe259, #ffa751) !important;
box-shadow: 0 16px 32px 0 rgb(128 99 66 / 25%) !important;
color: rgba(0, 0, 0, 0.95) !important;
opacity: 0;
animation: fadeIn 1s;
animation-delay: 2s;
animation-fill-mode: forwards;
pointer-events: none;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
<div id="button-y4sCSuA9ms">按钮文本</div>
关于CSS过渡和浏览器兼容性的更多信息,请参阅这个StackOverflow答案:
CSS transitions
英文:
Maybe you simply forgot to add keyframes for fadeIn
.
See snippet below, which will fade the button in after 2 seconds (to remove some wait time for you, just kick it back up to 5s):
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
div#button-y4sCSuA9ms {
background-image: linear-gradient(170deg, #ffe259, #ffa751) !important;
box-shadow: 0 16px 32px 0 rgb(128 99 66 / 25%) !important;
color: rgba(0, 0, 0, 0.95) !important;
opacity: 0;
animation: fadeIn 1s;
animation-delay: 2s;
animation-fill-mode: forwards;
pointer-events: none;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
<!-- language: lang-html -->
<div id="button-y4sCSuA9ms">Button text</div>
<!-- end snippet -->
See this StackOverflow answer about CSS transitions and browser compatibility for more information:
CSS transitions
答案2
得分: 0
通过在CSS中设置以下属性:
animation-iteration-count: infinite;
动画将每5秒重复一次(这是您设置的animation-delay属性)。
如果不想让动画永远重复播放,只需将animation-iteration-count设置为一个数字。
英文:
By setting
animation-iteration-count: infinite;
in the CSS, the animation keeps repeating every 5 seconds (the animation-delay property you have set).
If don't want the animation to keep repeating forever, just set the animation-iteration-count to a number.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论