gpt4 book ai didi

html - 在关键帧动画 CSS 中更改 div 的内容

转载 作者:可可西里 更新时间:2023-11-01 13:01:04 28 4
gpt4 key购买 nike

我有以下代码。

#mf-loader-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 500px;
height: 30px;
}
.mf-loader-circle {
position: absolute;
height: 30px;
width: 30px;
border-radius: 50%;
border: 2px solid #03C9A9;
top: -15px;
background: white;
text-align: center;
line-height: 30px;
color: #03C9A9;
}
.mf-loader-text {
position: absolute;
width: 150px;
top: 20px;
}
#one-text {
left: -10px;
-webkit-animation: cl 3s;
}
#two-text {
left: 200px;
-webkit-animation: cl 3s;
-webkit-animation-delay: 2s;
-webkit-animation-fill-mode: forwards;
color: rgba(1, 1, 1, 0);
}
#three-text {
left: 480px;
-webkit-animation: cl 3s;
-webkit-animation-delay: 3s;
-webkit-animation-fill-mode: forwards;
color: rgba(1, 1, 1, 0);
}
@-webkit-keyframes cl {
from {
color: rgba(1, 1, 1, 0);
}
to {
color: rgba(1, 1, 1, 1);
}
}
#two {
left: 240px;
}
#three {
left: 490px;
}
#mf-loader {
width: 100%;
height: 3px;
background: #03C9A9;
position: absolute;
-webkit-animation: mymove 5s;
/* Chrome, Safari, Opera */
animation: mymove 5s;
border-radius: 3px;
}
/* Chrome, Safari, Opera */

@-webkit-keyframes mymove {
0% {
width: 0px;
}
50% {
width: 50%;
}
100% {
width: 100%;
}
}
/* Standard syntax */

@keyframes mymove {
0% {
width: 0px;
}
50% {
width: 50%;
}
100% {
width: 100%;
}
}
<div id="mf-loader-container">

<div id="mf-loader">
<div class="mf-loader-circle" id="one">
1
</div>
<div class="mf-loader-circle" id="two">
2
</div>
<div class="mf-loader-circle" id="three">
3
</div>
<div class="mf-loader-text" id="one-text">
Each day will be better than last.
<br>This one especially
</div>
<div class="mf-loader-text" id="two-text">
Subscribing .. Thank you for subscribing. We appreciate it!
</div>
<div class="mf-loader-text" id="three-text">
DONE
</div>
</div>
</div>

这是一个类似结帐的动画 Action ,仅使用 CSS 完成。我试图在文本出现复选标记 后更改圆圈的内容 - 是否有任何方法可以使用 css 中的内容标签更改内容。

最佳答案

将内容(1、2、3 数字)更改为:after 伪元素并在那里设置内容。然后,将其应用于每个圆圈。这样,您可以通过更改 content:""; 将它们包含到您的动画中将“检查”更改为您需要的任何内容。

.mf-loader-circle:after {
position: absolute;
width: 100%;
height: 100%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
#one:after {
content: "1";
-webkit-animation: check1 3s;
-webkit-animation-fill-mode: forwards;
}
#two:after {
content: "2";
-webkit-animation: check2 3s;
-webkit-animation-delay: 2s;
-webkit-animation-fill-mode: forwards;
}
#three:after {
content: "3";
-webkit-animation: check3 3s;
-webkit-animation-delay: 3s;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes check1 {
from {
content: "1";
}
to {
content: "check";
}
}
@-webkit-keyframes check2 {
from {
content: "2";
}
to {
content: "check";
}
}
@-webkit-keyframes check3 {
from {
content: "3";
}
to {
content: "check";
}
}
#mf-loader-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 500px;
height: 30px;
}
.mf-loader-circle {
position: absolute;
height: 30px;
width: 30px;
border-radius: 50%;
border: 2px solid #03C9A9;
top: -15px;
background: white;
text-align: center;
line-height: 30px;
color: #03C9A9;
}
.mf-loader-text {
position: absolute;
width: 150px;
top: 20px;
}
#one-text {
left: -10px;
-webkit-animation: cl 3s;
}
#two-text {
left: 200px;
-webkit-animation: cl 3s;
-webkit-animation-delay: 2s;
-webkit-animation-fill-mode: forwards;
color: rgba(1, 1, 1, 0);
}
#three-text {
left: 480px;
-webkit-animation: cl 3s;
-webkit-animation-delay: 3s;
-webkit-animation-fill-mode: forwards;
color: rgba(1, 1, 1, 0);
}
@-webkit-keyframes cl {
from {
color: rgba(1, 1, 1, 0);
}
to {
color: rgba(1, 1, 1, 1);
}
}
#two {
left: 240px;
}
#three {
left: 490px;
}
#mf-loader {
width: 100%;
height: 3px;
background: #03C9A9;
position: absolute;
-webkit-animation: mymove 5s;
/* Chrome, Safari, Opera */
animation: mymove 5s;
border-radius: 3px;
}
/* Chrome, Safari, Opera */

@-webkit-keyframes mymove {
0% {
width: 0px;
}
50% {
width: 50%;
}
100% {
width: 100%;
}
}
/* Standard syntax */

@keyframes mymove {
0% {
width: 0px;
}
50% {
width: 50%;
}
100% {
width: 100%;
}
}
<div id="mf-loader-container">

<div id="mf-loader">
<div class="mf-loader-circle" id="one">
</div>
<div class="mf-loader-circle" id="two">
</div>
<div class="mf-loader-circle" id="three">
</div>
<div class="mf-loader-text" id="one-text">
Each day will be better than last.
<br>This one especially
</div>
<div class="mf-loader-text" id="two-text">
Subscribing .. Thank you for subscribing. We appreciate it!
</div>
<div class="mf-loader-text" id="three-text">
DONE
</div>
</div>
</div>

以下是变更摘要:


  • 在 HTML 中从您的圈子中删除了内容。

  • 创建了一个 :after 伪元素,对你所有的圈子都是通用的。

.mf-loader-circle:after {
position:absolute;
width:100%;
height:100%;
left:50%;
top:50%;
transform:translate(-50%, -50%);
}

在这里,我使用 2D 变换通过 position:absolute;

将数字定位在中心
  • 使用元素的 ID 将每个 content:""; 属性设置为必要的数字。

  • 为不同的数字创建动画,例如:


#one:after {
content:"1";
-webkit-animation: check1 3s;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes check1{
from {
content:"1";
}
to {
content:"check";
}
}

注意:添加相应的供应商前缀。

关于html - 在关键帧动画 CSS 中更改 div 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148112/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com