-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowcase.js
120 lines (103 loc) · 3.11 KB
/
showcase.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
gsap.registerPlugin(ScrollTrigger)
const images = Array.from(document.querySelectorAll(".img video"))
// console.log(images)
function addImageScaleAnimation(){
gsap.utils.toArray("section").forEach((section , index) => {
const image = images[index]
// console.log(image)
const startCondtion = index === 0 ? "top top" : "bottom bottom"
gsap.to(
image,
{
scrollTrigger : {
trigger : section ,
start : startCondtion,
end: ()=>{
const viewportHeight = window.innerHeight
const sectionBottom = section.offsetTop + section.offsetHeight
const additionalDistance = viewportHeight * 0.5
const endValue = sectionBottom - viewportHeight + additionalDistance
return `+=${endValue}`
} ,
scrub: 1
},
// scale: 3,
ease: "none"
}
)
})
}
addImageScaleAnimation()
function animateClipPath(
sectionId,
previewId,
startClipPath,
endClipPath,
start = "top center",
end = "bottom top"
){
let section = document.querySelector(sectionId)
let preview = document.querySelector(previewId)
ScrollTrigger.create({
trigger: section,
start: start,
end: end,
onEnter : () => {
gsap.to(preview , {
scrollTrigger : {
trigger : section,
start: start,
end: end,
scrub: 0.125
},
clipPath: endClipPath,
ease : "none"
})
}
})
}
const totalSection = 7
animateClipPath(
'#section1',
'#section1-preview',
"polygon(0% 100%,100% 100%,100% 100%,0% 100%)",
"polygon(0% 0%,100% 0%,100% 100%,0% 100%)"
)
for(let i = 2 ; i<=totalSection ; i++)
{
let currentSection = `#section${i}`
let prevPreview = `#section${i-1}-preview`
let currentPreview = `#section${i}-preview`
animateClipPath(
currentSection,
prevPreview,
"polygon(0% 0%,100% 0%,100% 100%,0% 100%)",
"polygon(0% 0%,100% 0%,100% 0%,0% 0%)",
"top bottom",
"center center"
)
if(i<totalSection)
{
animateClipPath(
currentSection,
prevPreview,
"polygon(0% 100%,100% 100%,100% 100%,0% 100%)",
"polygon(0% 0%,100% 0%,100% 100%,0% 100%)",
"center center",
"bottom top"
)
}
}
// const cover = document.querySelector(".cover")
// cover.addEventListener("click" , ()=>{
// console.log("clicked")
// })
// document.addEventListener('scroll', function(event) {
// console.log("ok")
// // Prevent default scroll behavior
// event.preventDefault();
// // Calculate the amount to scroll
// var scrollDelta = event.deltaY || event.detail || (-event.wheelDelta);
// // Manually scroll the page
// document.scrollBy(0, scrollDelta);
// });