-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
145 lines (127 loc) · 4.45 KB
/
Copy pathscript.js
File metadata and controls
145 lines (127 loc) · 4.45 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var tl = gsap.timeline({
});
tl.from("nav>h1",{
x:"-100%",
scale: 0.8,
opacity:0,
duration:1,
ease:"back.out(1)"
})
function locomotive(){
// Initialize Locomotive Scroll
const locoScroll = new LocomotiveScroll({
el: document.querySelector('main'), // The container for smooth scrolling
smooth: true, // Enable smooth scrolling
multiplier: 0.45, // Adjust scroll speed
lerp: 0.04, // Linear interpolation for smooth scroll (lower is smoother)
// getDirection: true, // Get scroll direction
// getSpeed: true, // Get scroll speed
// You might need to adjust these based on your layout and content
tablet: { smooth: true }, // Enable smooth scroll on tablets
mobile: { smooth: true } // Enable smooth scroll on mobiles
});
// Register GSAP ScrollTrigger plugin
gsap.registerPlugin(ScrollTrigger);
// --- ScrollTrigger Proxy for Locomotive Scroll ---
// This is the crucial part that makes GSAP ScrollTrigger work with Locomotive Scroll.
// It tells ScrollTrigger to use Locomotive Scroll's scroll position instead of the native browser scroll.
ScrollTrigger.scrollerProxy("main", {
scrollTop(value) {
return arguments.length ? locoScroll.scrollTo(value, { duration: 0, disableLerp: true }) : locoScroll.scroll.instance.scroll.y;
}, // We don't want to smooth scroll to the position, so duration: 0
getBoundingClientRect() {
return { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight };
},
// LocomotiveScroll handles pinning with transforms, so we must pinType: "transform"
pinType: document.querySelector("main").style.transform ? "transform" : "fixed"
});
// --- Event Listeners for Updates and Refresh ---
// Update ScrollTrigger when Locomotive Scroll updates (e.g., on scroll, resize, content changes)
locoScroll.on("scroll", ScrollTrigger.update);
// Refresh ScrollTrigger when Locomotive Scroll's internal state changes (e.g., on resize)
locoScroll.on("resize", () => {
ScrollTrigger.refresh();
});
// --- Set default scroller for all ScrollTriggers ---
// This ensures all subsequent ScrollTrigger animations use the Locomotive Scroll instance
ScrollTrigger.defaults({
scroller: "main"
});
}
locomotive();
let pages = document.querySelectorAll(".wrapper");
var pages_anim = gsap.timeline();
if(window.innerWidth>700){
pages.forEach((page)=>{
// page.setAttribute('data-scroll-speed',"-5");
gsap.fromTo(page,
{ scale: 0.8, opacity: 0.4 },
{
keyframes: [
{ scale: 1, opacity: 1, at: 0.5 }, // middle
{ scale: 1, opacity: 1, at: 1 }, // middle
{ scale: 0.8, opacity: 0.4 } // leaving
],
scrollTrigger: {
trigger: page,
start: "top 80%",
end: "top 0%",
scrub: true,
scroller: "main",
// markers: true
}
}
);
// gsap.fromTo(page,{
// scale:0.8,
// opacity:0.4
// }, {opacity:1,
// scale:1,
// zIndex:"-1",
// // stagger:0.5,
// scrollTrigger:{
// start: "0% 80%",
// end: "0% 30%",
// markers: true,
// scroller: "main",
// trigger: page,
// scrub:true,
// // pin:true
// }
// })
// gsap.to(page,{
// opacity:0.4,
// scale:0.8,
// // zIndex:"-1",
// // stagger:0.5,
// scrollTrigger:{
// start: "0% 20%",
// end: "top bottom",
// markers: true,
// scroller: "main",
// trigger: page,
// scrub:true,
// // pin:true
// }
// })
})
}
else{
// pages.forEach((page)=>{
// gsap.to(page,{
// opacity:0.4,
// scale:0.8,
// zIndex:"-1",
// stagger:0.5,
// scrollTrigger:{
// start: "20% 20%",
// end: "top 0%",
// // markers: true,
// scroller: "main",
// trigger: ".pages",
// scrub:true,
// pin:true
// }
// })
// })
}