-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
182 lines (146 loc) · 3.97 KB
/
script.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function init() {
gsap.registerPlugin(ScrollTrigger);
const locoScroll = new LocomotiveScroll({
el: document.querySelector("main"),
smooth: true,
lerp: 0.03,
multiplier: 0.7
});
locoScroll.on("scroll", ScrollTrigger.update);
ScrollTrigger.scrollerProxy("main", {
scrollTop(value) {
return arguments.length ? locoScroll.scrollTo(value, 0, 0) : locoScroll.scroll.instance.scroll.y;
},
getBoundingClientRect() {
return { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight };
},
pinType: document.querySelector("main").style.transform ? "transform" : "fixed"
});
ScrollTrigger.addEventListener("refresh", () => locoScroll.update());
ScrollTrigger.refresh();
}
init();
document.querySelectorAll('.elem').forEach(elem => {
elem.addEventListener('mouseenter', () => {
elem.style.zIndex = '10';
});
elem.addEventListener('mouseleave', () => {
elem.style.zIndex = '1';
});
});
let cursor = document.querySelector(".cursor");
let main = document.querySelector("main");
let cursorX = 0;
let cursorY = 0;
let currentX = 0;
let currentY = 0;
document.addEventListener("mousemove", function (dets) {
cursorX = dets.x;
cursorY = dets.y;
});
function animateCursor() {
const ease = 0.15;
currentX += (cursorX - currentX) * ease;
currentY += (cursorY - currentY) * ease;
cursor.style.left = currentX + "px";
cursor.style.top = currentY + "px";
requestAnimationFrame(animateCursor);
}
animateCursor();
let tl = gsap.timeline({
scrollTrigger: {
trigger: "#page-1 h1",
scroller: "main",
ease: Power0.easeOut,
start: "top 25%",
end: "top 0",
scrub: 3
}
})
tl.to("#page-1 h1", {
x: -100,
duration: 1,
}, "anm")
tl.to("#page-1 h2", {
x: 100,
duration: 1,
}, "anm")
tl.to("#page-1 #v-container", {
width: "90%",
duration: 1,
ease: Power0.easeOut
}, "anm")
let tl2 = gsap.timeline({
scrollTrigger: {
trigger: "#page-2",
scroller: "main",
start: "top 40%",
end: "top -60%",
scrub: 2
}
})
tl2.to("main", {
backgroundColor: "#fff",
color: "#111"
})
let tl3 = gsap.timeline({
scrollTrigger: {
trigger: "#page-4",
scroller: "main",
start: "top 40%",
end: "top -40%"
}
})
tl3.to("main", {
backgroundColor: "#000",
color: "#fff"
})
const boxes = document.querySelectorAll(".box");
boxes.forEach(function (elem) {
elem.addEventListener("mouseenter", function () {
const img = elem.getAttribute("data-image");
cursor.style.width = "300px";
cursor.style.height = "240px";
cursor.style.borderRadius = "10px";
cursor.style.backgroundSize = "cover";
cursor.style.backgroundImage = `url(${img})`;
});
elem.addEventListener("mouseleave", function () {
cursor.style.width = "20px";
cursor.style.height = "20px";
cursor.style.borderRadius = "50%";
cursor.style.backgroundImage = "none";
});
});
let h4 = document.querySelectorAll("#nav-part2 h4")
h4.forEach(function (elem) {
elem.addEventListener("mouseenter", function () {
const purple = document.querySelector("#purple")
purple.style.display = "block"
purple.style.opacity = "1"
if (!purple.querySelector('.marquee')) {
const marquee = document.createElement('div')
marquee.classList.add('marquee')
const span1 = document.createElement('span')
const span2 = document.createElement('span')
const navText = `${elem.textContent} `.repeat(100)
span1.textContent = navText
span2.textContent = navText
marquee.appendChild(span1)
marquee.appendChild(span2)
purple.appendChild(marquee)
marquee.style.animation = 'none'
marquee.offsetHeight
marquee.style.animation = null
}
})
elem.addEventListener("mouseleave", function () {
const purple = document.querySelector("#purple")
purple.style.display = "none"
purple.style.opacity = "0"
const marquee = purple.querySelector('.marquee')
if (marquee) {
purple.removeChild(marquee)
}
})
})