我试图得到一个横幅放置在一个HTML页面使用CSS动画运行计数器到一个特定的数字,但有一个有点问题时,试图得到一个以上的工作在同一横幅,数字将计数到不同的数额取决于div,第一次try 实现这一点,并将感谢任何帮助.
html,
body {
width: 100%;
height: 100%;
}
* {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
font-family: roboto, segoe ui, Verdena, Helvetica, Sans-Serif;
font-size: 16px;
/*text-transform: uppercase;
color: #000; */
}
@property --num {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
div span.years-number {
animation: counter 5s forwards ease-in-out;
counter-reset: num var(--num);
font: 800 40px system-ui;
padding: 2rem;
}
div span.years-number::after {
content: counter(num);
}
@keyframes counter {
from {
--num: 0;
}
to {
--num: 20;
}
}
div span.project-number::after {
content: counter(num);
}
@keyframes counter {
from {
--num: 0;
}
to {
--num: 55;
}
}
div span.employee-number::after {
content: counter(num);
}
@keyframes counter {
from {
--num: 0;
}
to {
--num: 10;
}
}
div span.customers-number::after {
content: counter(num);
}
@keyframes counter {
from {
--num: 0;
}
to {
--num: 115;
}
}
<section style="position: relative; z-index: 1; text-align: center;">
<div style="flex: 0 0 auto; width: 25%; scroll-behavior: inherit !important;">
<div class="single-counter">
<div class="counter-contents">
<h2 style="color: #000000; font-size: 45px; font-weight: 700; margin-bottom: 5px; word-spacing: -10px;">
<span class="years-number"></span>
<span>+</span>
</h2>
<h3 style="color: #000; font-size: 20px; font-weight: 600;">Years of Experience</h3>
</div>
</div>
</div>
<div style="flex: 0 0 auto; width: 25%; scroll-behavior: inherit !important;">
<div class="single-counter">
<div class="counter-contents">
<h2 style="color: #000; font-size: 45px; font-weight: 700; margin-bottom: 5px; word-spacing: -10px;">
<span class="project-number"></span>
<span>+</span>
</h2>
<h3 style="color: #000; font-size: 20px; font-weight: 600;">Complete Project</h3>
</div>
</div>
</div>
<div style="flex: 0 0 auto; width: 25%; scroll-behavior: inherit !important;">
<div class="single-counter">
<div class="counter-contents">
<h2 style="color: #000; font-size: 45px; font-weight: 700; margin-bottom: 5px; word-spacing: -10px;">
<span class="employee-number"></span>
<span>+</span>
</h2>
<h3 style="color: #000; font-size: 20px; font-weight: 600;">Employees</h3>
</div>
</div>
</div>
<div style="flex: 0 0 auto; width: 25%; scroll-behavior: inherit !important;">
<div class="single-counter">
<div class="counter-contents">
<h2 style="color: #000; font-size: 45px; font-weight: 700; margin-bottom: 5px; word-spacing: -10px;">
<span class="customers-number"></span>
<span>+</span>
</h2>
<h3 style="color: #000; font-size: 20px; font-weight: 600;">Customers</h3>
</div>
</div>
</div>
</section>