-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript3.js
97 lines (50 loc) · 1.53 KB
/
script3.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
// learn what all this code means at
// https://www.creativecodingclub.com/bundles/creative-coding-club
// unlock over 250 GSAP lessons today
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",
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,
scrub:true,
markers:false
})
})
return () => { // optional
// custom cleanup code here (runs when it STOPS matching)
console.log("mobile")
};
});
/* ScrollTrigger Docs
https://greensock.com/docs/v3/Plugins/ScrollTrigger
*/
/*
learn more GreenSock and ScrollTrigger
https://www.creativeCodingClub.com
new lessons weekly
less than $1 per week
*/