-
Notifications
You must be signed in to change notification settings - Fork 0
/
script1.js
112 lines (79 loc) · 2.31 KB
/
script1.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
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
const container = document.querySelector(".container");
const sections = gsap.utils.toArray(".container section");
const texts = gsap.utils.toArray(".anim");
const mask = document.querySelector(".mask");
let scrollTween = gsap.to(sections, {
xPercent: -100 * (sections.length - 1),
ease: "none",
scrollTrigger: {
trigger: ".container",
pin: true,
scrub: 2,
end: "+=3000",
//snap: 1 / (sections.length - 1),
toggleActions: 'play reverse play reverse',
markers: false,
}
});
// whizz around the sections
sections.forEach((section) => {
// grab the scoped text
let text = section.querySelectorAll(".anim");
// bump out if there's no items to animate
if(text.length === 0) return
// do a little stagger
gsap.from(text, {
y: -130,
opacity: 0,
duration: 4,
ease: "circ.out",
stagger: 0.1,
scrollTrigger: {
trigger: section,
containerAnimation: scrollTween,
start: "left center",
toggleActions: 'play reverse play reverse',
markers: false
}
});
});
const details = gsap.utils.toArray(".desktopContentSection:not(:first-child)")
const photos = gsap.utils.toArray(".desktopPhoto:not(:first-child)")
gsap.set(photos, {yPercent:101})
const allPhotos = gsap.utils.toArray(".desktopPhoto")
// create
let mm = gsap.matchMedia();
// add a media query. When it matches, the associated function will run
mm.add("(min-width: 600px)", () => {
// this setup code only runs when viewport is at least 600px wide
console.log("desktop")
ScrollTrigger.create({
trigger:".gallery",
start:"top top",
end:"bottom bottom",
toggleActions: 'play reverse play reverse',
pin:".right"
})
//create scrolltrigger for each details section
//trigger photo animation when headline of each details section
//reaches 80% of window height
details.forEach((detail, index)=> {
let headline = detail.querySelector("h1")
let animation = gsap.timeline()
.to(photos[index], {yPercent:0})
.set(allPhotos[index], {autoAlpha:0})
ScrollTrigger.create({
trigger:headline,
start:"top 80%",
end:"top 50%",
animation:animation,
toggleActions: 'play reverse play reverse',
scrub:true,
markers:false
})
})
return () => { // optional
// custom cleanup code here (runs when it STOPS matching)
console.log("mobile")
};
});