-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript .js
More file actions
146 lines (131 loc) · 3.77 KB
/
script .js
File metadata and controls
146 lines (131 loc) · 3.77 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
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
const gsap = window.gsap
const ScrollTrigger = window.ScrollTrigger
//theme management
const themeToggle = document.getElementById("themeToggle")
const body = document.body;
const currentTheme = localStorage.getItem("theme")|| "dark"
body.setAttribute("data-theme",currentTheme)
themeToggle.addEventListener("click",() => {
const currentTheme = body.getAttribute("data-theme")
const newTheme = currentTheme === "dark" ? "light" : "dark"
body.setAttribute("data-theme",newTheme)
localStorage.setItem("theme",newTheme)
//Animate theme toggle
gsap.to(themeToggle,{
scale:0.9,
duration:0.3,
yoyo:true,
repeat:1,
ease:"power2.inOut"
})
})
//mobile menu management
const menuToggle = document.getElementById("menuToggle")
const mobileMenu = document.getElementById("mobileMenu")
menuToggle.addEventListener("click",()=>{
menuToggle.classList.toggle("active")
mobileMenu.classList.toggle("active")
//prevent body scroll when menu is open
if (mobileMenu.classList.contains("active")){
body.style.overflow = "hidden"
}
else{
body.style.overflow = ""
}
})
//loading function
function initLoader(){
const loader = document.querySelector(".loader")
const loaderText = document.querySelector(".loader-text")
const loaderProgress = document.querySelector(".loader-progress")
//animation loader text
gsap.to(loaderText,{
opacity:1,
duration:0.7,
ease:"power2.out"
})
//animation progress bar
gsap.to(loaderProgress,{
width:"100%",
duration:2,
ease:"power2.inOut",
onComplete:()=> {
gsap.to(loader,{
opacity:0,
duration:0.7,
onComplete: () => {
loader.style.display = "none"
initAnimations()
}
})
}
})
}
//initialize loader on page load
window.addEventListener("load",initLoader)
//custom cursor(only on desktop)
if (window.innerWidth > 768){
const cursor = document.querySelector(".cursor")
const cursorFollower = document.querySelector(".cursor-follower")
document.addEventListener("mousemove",(e)=> {
gsap.to(cursor,{
x:e.clientX - 10,
y:e.clientY - 10,
duration:0.1,
})
gsap.to(cursorFollower,{
x:e.clientX - 20,
y:e.clientY - 20,
duration:0.2,
})
})
}
//initialize all animations
function initAnimations(){
//Navigation animation
gsap.to("nav",{
y:0,
duration:1,
ease:"power3.out",
})
//Hero Animation
const heroTl = gsap.timeline()
heroTl
.to(".hero-title",{
opacity:1,
filter:'blur(0px)',
y:0,
duration:1.2,
ease: "power3.out"
})
.to(".hero-subtitle",{
opacity:1,
filter:'blur(0px)',
y:0,
duration:0.8,
ease:"power3.out"
}, "-=0.5")
.to(".hero-description",{
opacity:1,
filter:'blur(0px)',
y:0,
duration:0.8,
ease:"power3.out"
},"-=0.3")
// .to(".cta-button",{
// opacity:1,
// filter:"blur(0px)"
// y:0,
// duration:0.8,
// ease:"power3.out"
// },"-=0.3")
}
document.querySelectorAll('.card').forEach(card => {
card.addEventListener('mousemove', e => {
const rect = card.getBoundingClientRect();
// UPDATE CSS VARIABLES FOR THE SPOTLIGHT EFFECT
card.style.setProperty('--x', `${e.clientX - rect.left}px`);
card.style.setProperty('--y',`${e.clientY - rect.top}px`);
})
})
// mobile view for about