-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
137 lines (115 loc) · 5.02 KB
/
script.js
File metadata and controls
137 lines (115 loc) · 5.02 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
document.addEventListener('DOMContentLoaded', () => {
/* -------------------------------------
1. Custom Cursor Logic
------------------------------------- */
const cursor = document.getElementById('custom-cursor');
const hoverTargets = document.querySelectorAll('.hover-target, a, button');
// Only activate custom cursor on non-touch devices
if (window.matchMedia("(pointer: fine)").matches) {
document.addEventListener('mousemove', (e) => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
});
// Add hover effect states
hoverTargets.forEach(target => {
target.addEventListener('mouseenter', () => {
cursor.classList.add('cursor-hover');
});
target.addEventListener('mouseleave', () => {
cursor.classList.remove('cursor-hover');
});
});
} else {
// Disable custom cursor
if (cursor) cursor.style.display = 'none';
document.body.style.cursor = 'auto';
}
/* -------------------------------------
2. Magnetic Buttons
------------------------------------- */
const magneticBtns = document.querySelectorAll('.magnetic-btn');
magneticBtns.forEach(btn => {
btn.addEventListener('mousemove', (e) => {
const rect = btn.getBoundingClientRect();
// Calculate mouse position relative to button center
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
// Move button slightly towards cursor
btn.style.transform = `translate(${x * 0.2}px, ${y * 0.2}px)`;
});
btn.addEventListener('mouseleave', () => {
btn.style.transform = `translate(0px, 0px)`;
btn.style.transition = 'transform 0.5s ease';
});
btn.addEventListener('mouseenter', () => {
btn.style.transition = 'none';
});
});
/* -------------------------------------
3. 3D Glass Card Tilt & Glow Tracking
------------------------------------- */
const tiltCards = document.querySelectorAll('.tilt-card');
tiltCards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left; // x position within the element.
const y = e.clientY - rect.top; // y position within the element.
// Update CSS variables for the inner radial gradient glow
card.style.setProperty('--mouse-x', `${x}px`);
card.style.setProperty('--mouse-y', `${y}px`);
// Calculate 3D tilt
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = ((y - centerY) / centerY) * -10; // Max rotation 10deg
const rotateY = ((x - centerX) / centerX) * 10;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = `perspective(1000px) rotateX(0deg) rotateY(0deg)`;
card.style.transition = 'transform 0.5s ease';
});
card.addEventListener('mouseenter', () => {
card.style.transition = 'none';
});
});
/* -------------------------------------
4. Scroll Reveal Intersection Observer
------------------------------------- */
const observerOptions = {
threshold: 0.1,
rootMargin: "0px 0px -50px 0px"
};
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// We do not unobserve, allowing elements to fade back out if desired,
// but usually you unobserve.
revealObserver.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.reveal').forEach((element) => {
revealObserver.observe(element);
});
/* -------------------------------------
5. Form Handling Override
------------------------------------- */
const newsForm = document.querySelector('.news-box');
if (newsForm) {
newsForm.addEventListener('submit', (e) => {
e.preventDefault();
const btn = newsForm.querySelector('button');
const originalText = btn.textContent;
btn.textContent = "Access Requested!";
btn.style.background = "var(--secondary)";
btn.style.color = "var(--bg-base)";
setTimeout(() => {
btn.textContent = originalText;
btn.style.background = "";
btn.style.color = "";
newsForm.reset();
}, 3000);
});
}
});