Last active
November 8, 2024 15:58
-
-
Save Golgrax/5b2f02901f77f17f0f5848ded8c450e2 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Your Page Title</title> | |
<link href="https://codepen.io/GreenSock/pen/xxmzBrw.css" rel="stylesheet" /> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<div id="particles-js"></div> | |
<div class="wrapper"> | |
<div class="content"> | |
<div class="section hero"></div> | |
<div class="section hero layer-2"></div> | |
<div class="image-container"> | |
<img src="https://media.discordapp.net/attachments/799467932082110465/1304457418314354719/IMG_0360.png?ex=672f7624&is=672e24a4&hm=207e4a0c41e29d4e11d2bb325eb0df66c86c479fa0773034380546ea66440f64" alt="Sample Image"> | |
</div> | |
</div> | |
</div> | |
<script src="https://unpkg.com/gsap@3/dist/gsap.min.js"></script> | |
<script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/particles.js"></script> | |
<script src="script.js"></script> | |
</body> | |
</html> |
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" | |
}, | |
"<" | |
) | |
.to( | |
".section.hero.layer-2", | |
{ | |
scale: 1.2, | |
transformOrigin: "center center", | |
ease: "power1.inOut", | |
opacity: 1 | |
}, | |
"<" | |
); | |
}); | |
particlesJS('particles-js', { | |
particles: { | |
number: { | |
value: 100, | |
density: { | |
enable: true, | |
value_area: 800 | |
} | |
}, | |
color: { | |
value: "#ffffff" | |
}, | |
shape: { | |
type: "circle", | |
stroke: { | |
width: 0, | |
color: "#000000" | |
} | |
}, | |
opacity: { | |
value: 0.5, | |
random: true, | |
anim: { | |
enable: true, | |
speed: 1, | |
opacity_min: 0, | |
sync: false | |
} | |
}, | |
size: { | |
value: 3, | |
random: true, | |
anim: { | |
enable: false, | |
speed: 4, | |
size_min: 0.3, | |
sync: false | |
} | |
}, | |
line_linked: { | |
enable: true, | |
distance: 100, | |
color: "#ffffff", | |
opacity: 0.5, | |
width: 1 | |
}, | |
move: { | |
enable: true, | |
speed: 2, | |
direction: "none", | |
random: true, | |
straight: false, | |
out_mode: "out", | |
bounce: false, | |
attract: { | |
enable: false, | |
rotateX: 600, | |
rotateY: 600 | |
} | |
} | |
}, | |
interactivity: { | |
detect_on: "canvas", | |
events: { | |
onhover: { | |
enable: true, | |
mode: "repulse" | |
}, | |
onclick: { | |
enable: true, | |
mode: "push" | |
}, | |
resize: true | |
} | |
}, | |
retina_detect: true | |
}); |
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; | |
} | |
body { | |
overflow: hidden; | |
} | |
#particles-js { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100vh; | |
z-index: -1; | |
} | |
.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://media.discordapp.net/attachments/799467932082110465/1304457418314354719/IMG_0360.png?ex=672f7624&is=672e24a4&hm=207e4a0c41e29d4e11d2bb325eb0df66c86c479fa0773034380546ea66440f64); | |
background-position: center center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
position: relative; | |
z-index: 1; | |
} | |
.content .section.hero.layer-2 { | |
background-image: url(https://media.discordapp.net/attachments/799467932082110465/1304457417685340231/Untitled5_20241108223835.png?ex=672f7624&is=672e24a4&hm=5bf13ae83c59e156ebc21009876e494107e4b283758fbb47b79a2d87df8cffde); | |
background-position: center center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
z-index: 3; | |
opacity: 0.7; | |
} | |
.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