**What I’m trying to do: I have some javascript that does an image reveal as the user scrolls to the bottom of the page, which works in plain html/js but fails in javascript.
**What I’ve tried and what’s not working: I tried placing this script in native libraries or waiting until my form loads before calling the js, but it all fails.
<style>
.reveal-image {
position: absolute;
width: 100%;
height: 500px;
background: url('https://picsum.photos/800/500') no-repeat center center/cover;
clip-path: inset(100% 0 0 0);
}
.footer {
background: #161b22;
padding: 20px;
text-align: center;
font-size: 14px;
color: #b9b9b9;
}
</style>
</div>
<div class="reveal-container">
<div class="reveal-image" id="scroll-image"></div>
</div>
<div class="footer">
<p>© 2024 TJ Watson. All rights reserved.</p>
</div>
<script>
function handleScrollReveal() {
let scrollPos = window.scrollY;
let revealImage = document.getElementById("scroll-image");
let maxHeight = 500;
let revealHeight = Math.min(maxHeight, scrollPos);
revealImage.style.clipPath = `inset(${maxHeight - revealHeight}px 0 0 0)`;
}
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("scroll", handleScrollReveal);
});
</script>