javascript - 如何将动画应用于元素直到滚动到它?

标签 javascript jquery html css

我的页面上有一些技能栏,如下所示: enter image description here

我使用以下 CSS 来制作动画。

.progress {
  height: 10px;
  background: #333;
  border-radius: 0;
  box-shadow: none;
  margin-bottom: 30px;
  overflow: visible;
}

.progress .progress-bar {
  position: relative;
  -webkit-animation: animate-positive 2s;
  animation: animate-positive 2s;
}

.progress .progress-bar:after {
  content: "";
  display: inline-block;
  width: 9px;
  background: #fff;
  position: absolute;
  top: -10px;
  bottom: -10px;
  right: -1px;
  z-index: 1;
  transform: rotate(35deg);
}

.progress .progress-value {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  position: absolute;
  top: -30px;
  right: -25px;
}

@-webkit-keyframes animate-positive {
  0% {
    width: 0;
  }
}

@keyframes animate-positive {
  0% {
    width: 0;
  }
}
<div class="progress">
  <div class="progress-bar" style="width:60%; background:linear-gradient(to bottom right, #a1c4fd, #c2e9fb);">
    <div class="progress-value">60%</div>
  </div>
</div>

如何让它们保持在 0% 直到我滚动到这部分?我知道 jQuery 中的 scrollTo 函数,但我不知道如何应用到这个函数。

最佳答案

您可以将 wowjs 与 animate.css 一起使用!它很简单,您可以在任何元素进入视口(viewport)时对其应用效果。它还为您提供了操纵动画延迟、动画持续时间等的选项。

以下是链接:

WowJS: http://mynameismatthieu.com/WOW/

AnimateCSS https://daneden.github.io/animate.css/

关于javascript - 如何将动画应用于元素直到滚动到它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261998/

相关文章:

javascript - 我收到 Auth0 Node 包中无法识别的函数的错误,特别是在其 AuthenticationClient 和 ManagementClient API 中

javascript - 为什么建议在构造函数中包含方法? - Javascript

html - 在输入文本框上放置固定文本

javascript - 使用默认的 .sort() 对 JavaScript 中所需的数组对象进行排序

javascript - 如何从传单 map 中删除多个标记并添加新标记?

javascript - jquery scrollTop 动画完成后滚动触发

javascript - 如何循环遍历 div 中的所有元素并查找包含文本的标签

javascript - NodeJS Multer 不工作

Javascript 在通过 XMLHttpRequest 加载时不执行,但在使用 jQuery.load 加载时执行

javascript - 如何在 API 调用中传递 key 作为授权 header