当用户滚动到页面的那一部分时,我只是想让以下代码的动画成为活动状态。这只需要发生一次,直到刷新页面,动画才会再次发生。
<ul class="skill-list">
<li class="skill">
<h3>Nunchucks</h3>
<progress class="skill-1" max="100" value="50">
<strong>Skill Level: 50%</strong>
</progress>
</li>
<li class="skill">
<h3>Bow Staff</h3>
<progress class="skill-2" max="100" value="75">
<strong>Skill Level: 75%</strong>
</progress>
</li>
<li class="skill">
<h3>Roundhouse Kick</h3>
<progress class="skill-3" max="100" value="25">
<strong>Skill Level: 25%</strong>
</progress>
</li>
</ul>
这是CSS:
<!-- skill chart -->
body {
font-family: 'Open Sans', sans-serif;
padding: 2em;
}
h1 {
font-size: 2em;
font-weight: 800;
}
h3 {
font-size: 2em;
}
progress, progress[role] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
background-size: auto;
height: 100px;
width: 100%;
}
.skill-list {
list-style: none;
margin: 0;
padding: 1em;
}
.skill {
margin-bottom: 1em;
position: relative;
}
.skill h3 {
color: #fff;
left: 1em;
line-height: 1;
position: absolute;
top: 1em;
}
.skill ::-webkit-progress-value {
-webkit-animation: bar-fill 2s;
width: 0px;
}
.skill-1::-webkit-progress-value {
background: #ff9e2c;
}
.skill-1::-moz-progress-bar {
background: #ff9e2c;
}
.skill-2::-webkit-progress-value {
background: #4ecdc4;
}
.skill-2::-moz-progress-bar {
background: #4ecdc4;
}
.skill-3::-webkit-progress-value {
background: #ff6b6b;
}
.skill-3::-moz-progress-bar {
background: #ff6b6b;
}
@-webkit-keyframes bar-fill {
0% {
width: 0;
}
}
@keyframes bar-fill {
0% {
width: 0;
}
}