-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.js
49 lines (41 loc) · 1.2 KB
/
animations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gsap from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import Lenis from "@studio-freight/lenis";
gsap.registerPlugin(ScrollTrigger);
// 🔹 Smooth Scroll Setup
const lenis = new Lenis({
smooth: true,
lerp: 0.1,
infinite: false,
});
function smoothScroll() {
lenis.on("scroll", () => ScrollTrigger.update());
gsap.ticker.add((time) => lenis.raf(time * 1000));
gsap.ticker.lagSmoothing(0);
}
smoothScroll();
// 🔹 3D Parallax Scroll Effect
gsap.utils.toArray(".parallax").forEach((layer) => {
gsap.to(layer, {
yPercent: -15,
ease: "none",
scrollTrigger: {
trigger: layer,
start: "top bottom",
scrub: true,
},
});
});
// 🔹 Magnetic Button Effect (For Smooth Hover)
const buttons = document.querySelectorAll(".magnetic-button");
buttons.forEach((button) => {
button.addEventListener("mousemove", (e) => {
const { left, top, width, height } = button.getBoundingClientRect();
const x = e.clientX - left - width / 2;
const y = e.clientY - top - height / 2;
gsap.to(button, { x: x * 0.3, y: y * 0.3, duration: 0.3 });
});
button.addEventListener("mouseleave", () => {
gsap.to(button, { x: 0, y: 0, duration: 0.3 });
});
});