Usa that one library, it automatically detects when you are scrolling down, but now something you will need to use is the data-aos-offset="pixels"
. There is another library that I used, I’m just not remembered, dps put here. It detects when the div is inside the window.
* { margin: 0; padding: 0; box-sizing: border-box; }
body { width: 100vw; height: 100vh; }
.nothing {
background: black;
width: 100%;
height: 100%;
}
.animated {
background: red;
width: 100%;
height: 100%;
}
<link href="https://unpkg.com/[email protected]/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/aos.js"></script>
<script>
window.onload = function() {
AOS.init()
}
</script>
<div class="nothing"></div>
<div class="animated" data-aos="fade-right" data-aos-offset="10"></div>
Go stir in the data-aos-offset
as each div needs, and of course take a look at documentation to put your own animations
Wouldn’t it be better to define one thing or another? For example, when the whole div appears on the screen?
– Sam
Well, I think it would work this idea of the whole div appearing on the screen, I hadn’t thought of that.
– Igor Mello
I’ll put an answer that detects when the whole div is on the screen.
– Sam