如何在屏幕上显示一个元素后立即更改其CSS属性

问题描述

一个问题,我看到一些网站,当您向下滚动页面时,出现了一些元素,这些元素开始修改属性,例如大小和位置。再次向上滚动时,这些元素将返回其原始大小和位置。

当元素出现在屏幕上时,是否可以修改CSS属性

解决方法

This youtube tutorial may help you out.

This project will give you the code you need.

下面是一个例子。

.animation1 {
  width: 100px;
  height: 100px;
  background-color: red;
  animation-name: example;
  animation-duration: 4s;
}
.animation2 {
  width: 100px;
  height: 100px;
  background-color: red;
 }
.space{
height:150vh;
}
@keyframes example {
  0%   {background-color: red;}
  25%  {background-color: yellow;}
  50%  {background-color: blue;}
  100% {background-color: green;}
}
<link href="https://unpkg.com/[email protected]/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/aos.js"></script>
<div class="animation1"></div>
<div class="space"></div>
<div class="animation2" data-aos="fade-up"
     data-aos-anchor-placement="center-bottom"
     data-aos-duration="2000">
</div>
<script>
  AOS.init();
</script>