Created
November 5, 2024 17:37
-
-
Save nathfavour/f19973b447e39d04c158ae8fb983e98c to your computer and use it in GitHub Desktop.
ScrollTrigger Image Zoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="wrapper"> | |
<div class="content"> | |
<section class="section hero"></section> | |
<section class="section gradient-purple"></section> | |
<section class="section gradient-blue"></section> | |
</div> | |
<div class="image-container"> | |
<img src="https://assets-global.website-files.com/63ec206c5542613e2e5aa784/643312a6bc4ac122fc4e3afa_main%20home.webp" alt="image"> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear(); | |
gsap.registerPlugin(ScrollTrigger); | |
window.addEventListener("load", () => { | |
gsap | |
.timeline({ | |
scrollTrigger: { | |
trigger: ".wrapper", | |
start: "top top", | |
end: "+=150%", | |
pin: true, | |
scrub: true, | |
markers: true | |
} | |
}) | |
.to("img", { | |
scale: 2, | |
z: 350, | |
transformOrigin: "center center", | |
ease: "power1.inOut" | |
}) | |
.to( | |
".section.hero", | |
{ | |
scale: 1.1, | |
transformOrigin: "center center", | |
ease: "power1.inOut" | |
}, | |
"<" | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/gsap@3/dist/gsap.min.js"></script> | |
<script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
.wrapper, | |
.content { | |
position: relative; | |
width: 100%; | |
z-index: 1; | |
} | |
.content { | |
overflow-x: hidden; | |
} | |
.content .section { | |
width: 100%; | |
height: 100vh; | |
} | |
.content .section.hero { | |
background-image: url(https://images.unsplash.com/photo-1589848315097-ba7b903cc1cc?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D); | |
background-position: center center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
} | |
.image-container { | |
width: 100%; | |
height: 100vh; | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
z-index: 2; | |
perspective: 500px; | |
overflow: hidden; | |
} | |
.image-container img { | |
width: 100%; | |
height: 100%; | |
object-fit: cover; | |
object-position: center center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://codepen.io/GreenSock/pen/xxmzBrw.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment