-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
144 lines (117 loc) · 3.18 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
const NewDate = document.querySelector(".date span");
const cursor = document.querySelector("#mini-circle");
const ELEM = document.querySelectorAll(".elem");
const loading = document.querySelector("#preloader");
const serviceCards = document.querySelectorAll('.service-card');
NewDate.innerHTML = new Date().getFullYear();
function cursorMaker(xscale = 1, yscale = 1) {
window.addEventListener("mousemove", function (event) {
gsap.to(cursor, {
x: event.clientX,
y: event.clientY,
scaleX: xscale,
scaleY: yscale,
duration: 0.5,
});
});
}
// Animation for first page load
function firstPageAnimation() {
const tl = gsap.timeline();
tl.to(["#nav a", "#nav h4"], {
y: 0,
duration: 0.3,
ease: "power2.out",
});
tl.to([".bounding h1", ".fitcontent h1"], {
y: 0,
duration: 0.5,
opacity: 0.5,
ease: "power2.out",
});
tl.to(".fitcontent p", {
y: 0,
duration: 0.3,
ease: "power2.out",
opacity: 1,
});
tl.to("#head p", {
y: 0,
duration: 0.5,
ease: "power2.out",
});
tl.from("#heroFooter", {
opacity: 0,
});
// Initialize service cards animation
}
function setupServiceCards() {
serviceCards.forEach((card, index) => {
gsap.from(card, {
opacity: 0,
y: 50,
scale:0,
duration: 1.5,
ease: "power2.out",
scrollTrigger: {
trigger: card,
start: "top 100%",
end: "top 100%",
toggleActions: "play none none reverse",
}
});
// Add hover animation
card.addEventListener('mouseenter', () => {
gsap.to(card, {
y: -10,
duration: 1.5,
ease: "power2.out"
});
});
card.addEventListener('mouseleave', () => {
gsap.to(card, {
y: 0,
duration: 1.5,
ease: "power2.out"
});
});
});
}
// Interactions with specific elements
ELEM.forEach(function (elem) {
elem.addEventListener("mousemove", function (event) {
const diff = event.clientY - elem.getBoundingClientRect().top;
gsap.to(elem.querySelector("img"), {
opacity: 1,
ease: Power1.easeInOut,
top: diff,
left: event.clientX,
});
cursor.classList.add("expand");
});
elem.addEventListener("mouseleave", function () {
cursor.classList.remove("expand");
});
});
// Initialization function
function init() {
// Initialize cursor
cursorMaker();
// Hide preloader
gsap.to(loading, {
opacity: 0,
duration: 0.5,
onComplete: () => {
loading.style.display = "none";
}
});
// Start first page animation
firstPageAnimation();
setupServiceCards();
}
// Start everything on load
window.addEventListener("load", init);
// Handle resize events
window.addEventListener("resize", () => {
ScrollTrigger.refresh();
});