如何延迟一个元素?

huangapple go评论62阅读模式
英文:

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 -->

&lt;div id=&quot;button-y4sCSuA9ms&quot;&gt;Button text&lt;/div&gt;

<!-- 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.

huangapple
  • 本文由 发表于 2023年7月12日 23:29:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76672217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定