Javascript 在视口中运行CSS关键帧动画
我正在尝试建立一个网站,我有一些关键帧动画来淡化我的文本。然而,动画在网站的开头就开始了。我要做的是仅在内容位于视口中时运行动画。是否可以仅在CSS和HTML中执行此操作?或者如果我需要javascript,如何使用 这就是我到目前为止所做的: 我的HTMLJavascript 在视口中运行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
<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;
}