-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
61 lines (50 loc) · 2.14 KB
/
Copy pathscripts.js
File metadata and controls
61 lines (50 loc) · 2.14 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
document.addEventListener("DOMContentLoaded", () => {
if (window.innerWidth > 767) {
gsap.registerPlugin(ScrollTrigger);
const mediaElements = document.querySelectorAll(".media img, .media video");
// Set all media elements to be initially invisible!
gsap.set(mediaElements, {y: '100%', opacity: 0, visibility: 'visible' });
document.querySelectorAll(".article section").forEach((section) => {
const mediaId = section.getAttribute('data-media');
const mediaElement = document.getElementById(mediaId);
if (mediaElement) {
ScrollTrigger.create({
trigger: section,
start: 'top center',
end: 'bottom center',
onEnter: () => {
gsap.to(mediaElement, {y: '0%', opacity: 1, duration: 0.5, ease: 'power1.out' });
},
onLeave: () => {
gsap.to(mediaElement, {y: '-100%', opacity: 0, duration: 0.5, ease: 'power1.in' });
},
onEnterBack: () => {
gsap.to(mediaElement, {y: '0%', opacity: 1, duration: 0.5, ease: 'power1.out' });
},
onLeaveBack: () => {
gsap.to(mediaElement, {y: '100%', opacity: 0, duration: 0.5, ease: 'power1.in' });
}
});
}
});
} else {
document.querySelectorAll(".article section").forEach((section) => {
const mediaId = section.getAttribute('data-media');
const mediaElement = document.getElementById(mediaId);
if (mediaElement) {
section.appendChild(mediaElement);
gsap.set(mediaElement, {
clearProps: "all",
opacity: 1,
visibility: "visible",
y: 0,
position: "static",
float: "right",
margin: "10px",
width: "100%",
maxWidth: "100%",
});
}
});
}
});