<div class='container'>
<div class='reveal'>
<img src='https://images.unsplash.com/photo-1526413232644-8a40f03cc03b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80%20634w'>
</div>
</div>
<div class='container'>
<div class='reveal'>
<img src='https://images.unsplash.com/photo-1505201372024-aedc618d47c3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80%20634w'>
</div>
</div>
<div class='container'>
<div class='reveal'>
<img src='https://images.unsplash.com/photo-1531727991582-cfd25ce79613?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80%20634w'>
</div>
</div>
<div class='container'>
<div class='reveal'>
<img src='https://images.unsplash.com/photo-1580215935060-a5adc57c5157?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80'>
</div>
<div class="credit"><a href="https://thisisadvantage.com" target="_blank">Made by Advantage</div>
</div>
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
position: relative;
}
.container:nth-child(1) {
background: #b6916d;
}
.container:nth-child(2) {
background: #bcb8ad;
}
.container:nth-child(3) {
background: #b69187;
}
.container:nth-child(4) {
background: #3c564f;
}
img {
height: 100%;
width: 100%;
object-fit: cover;
transform-origin: left;
}
.reveal {
visibility: hidden;
position: relative;
width: 80%;
height: 80%;
max-width: 500px;
overflow: hidden;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.credit {
font-family: Termina, sans-serif;
position: absolute;
bottom: 10px;
a {
color: white;
}
}
View Compiled
gsap.registerPlugin(ScrollTrigger);
let revealContainers = document.querySelectorAll(".reveal");
revealContainers.forEach((container) => {
let image = container.querySelector("img");
let tl = gsap.timeline({
scrollTrigger: {
trigger: container,
toggleActions: "restart none none reset"
}
});
tl.set(container, { autoAlpha: 1 });
tl.from(container, 1.5, {
xPercent: -100,
ease: Power2.out
});
tl.from(image, 1.5, {
xPercent: 100,
scale: 1.3,
delay: -1.5,
ease: Power2.out
});
});
// OLD WAY USING INTERSECTION OBSERVER API AND CLIP-PATH
/*const options = {
root: null,
rootMargin: "0px",
threshold: 0.9
};
let revealCallback = (entries, self) => {
entries.forEach(entry => {
let container = entry.target;
let img = entry.target.querySelector("img");
const easeInOut = "power3.out";
const revealAnim = gsap.timeline({ ease: easeInOut });
if (entry.isIntersecting) {
revealAnim.set(container, {
visibility: "visible"
});
revealAnim.fromTo(
container,
{
clipPath: "polygon(0 0, 0 0, 0 100%, 0% 100%)",
webkitClipPath: "polygon(0 0, 0 0, 0 100%, 0% 100%)"
},
{
clipPath: "polygon(0 0, 100% 0, 100% 100%, 0 100%)",
webkitClipPath: "polygon(0 0, 100% 0, 100% 100%, 0 100%)",
duration: 1,
ease: easeInOut
}
);
revealAnim.from(img, 4, {
scale: 1.4,
ease: easeInOut,
delay: -1
});
self.unobserve(entry.target);
}
});
};
let revealObserver = new IntersectionObserver(revealCallback, options);
document.querySelectorAll(".reveal").forEach(reveal => {
revealObserver.observe(reveal);
});
*/