I'm currently experimenting with creating a cool effect on my website where an image fades in and moves up as the user scrolls it into view. I've included the code I have so far below, but unfortunately, I keep getting a 404 error when trying to run it. Any help would be greatly appreciated! I'm still new to JavaScript and have been working hard to understand this.
Check out my CSS:
.section3 {
opacity: 0;
transform: translateY(20vh);
visibility: hidden;
transition: opacity 0.6s ease-out, transform 1.2s ease-out;
will-change: opacity, visibility;
}
.fade {
opacity: 1;
transform: none;
visibility: visible;
}
Here is how the HTML and JS are structured:
<section id="section3" class="section3">
<img style="width: 100%;" src="lovethyneighbor.jpg">
</section>
<script>
var section3 = document.getElementById("section3");
var location = section3.getBoundingClientRect();
if (location.top >= 0) {
document.getElementById("section3").classList.add("fade");
} else {
document.getElementById("section3").classList.add("section3");
}
</script>