Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在视口中运行CSS关键帧动画_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 在视口中运行CSS关键帧动画

Javascript 在视口中运行CSS关键帧动画,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在尝试建立一个网站,我有一些关键帧动画来淡化我的文本。然而,动画在网站的开头就开始了。我要做的是仅在内容位于视口中时运行动画。是否可以仅在CSS和HTML中执行此操作?或者如果我需要javascript,如何使用 这就是我到目前为止所做的: 我的HTML <div class="section_container"> <div style="background-color:red" class="section"> <h1 class="anima

我正在尝试建立一个网站,我有一些关键帧动画来淡化我的文本。然而,动画在网站的开头就开始了。我要做的是仅在内容位于视口中时运行动画。是否可以仅在CSS和HTML中执行此操作?或者如果我需要javascript,如何使用

这就是我到目前为止所做的:

我的HTML

<div class="section_container">
  <div style="background-color:red" class="section">
    <h1 class="animate_fadeup">Page1</h1>
  </div>
  <div style="background-color:green" class="section">
    <h1 class="animate_fadeup">Page2</h1>
  </div>
  <div style="background-color:blue" class="section">
    <h1 class="animate_fadeup">Page3</h1>
  </div>
</div>
或者看看我的密码笔:

检查此库您也可以检查库。或者使用自定义javascript函数了解元素是否在视口中。
.section_container {
  width: 100%;
  max-height: 100vh;
  overflow-y: scroll;
  border: 1px solid gray;
  scroll-snap-type: y mandatory;
  &.proximity {
    scroll-snap-type: y proximity;
  }
}
.section {
  border-bottom: 1px solid white;
  height: 100vh;
  font-size: 1.4rem;
  color: rgba(white, .5);
  text-align: center;
  scroll-snap-align: start;
  display: flex;
  flex-flow: column;
  justify-content: start;
}

/* Animations */
@keyframes fadeup {
  0% {
    bottom: -50px;
    opacity: 0.1;
  }
  100% {
    bottom: 0px;
    opacity: 1;
  }
}
.animate_fadeup {
  animation-name: fadeup;
  animation-duration: 3s;
  animation-fill-mode: both;
  position: relative;
}