首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当用户滚动到页面的该部分时激活CSS动画

当用户滚动到页面的该部分时激活CSS动画
EN

Stack Overflow用户
提问于 2015-03-03 07:11:21
回答 1查看 157关注 0票数 1

我只是想让下面代码的动画在用户滚动到页面的那个部分时变得活动起来。这只需要发生一次,直到页面刷新,动画可以再次发生。

代码语言:javascript
复制
    <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:

代码语言:javascript
复制
<!-- 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;
  }
}
EN

回答 1

Stack Overflow用户

发布于 2015-03-03 07:15:44

您需要一个可以跟踪滚动位置的脚本,这里是wow.js

https://github.com/matthieua/WOW

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28821160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档