-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (68 loc) · 2.74 KB
/
script.js
File metadata and controls
82 lines (68 loc) · 2.74 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
// for spotlight effect on cursor
document.addEventListener("DOMContentLoaded", () => {
const spotlight = document.getElementById("spotlight");
document.addEventListener("mousemove", (e) => {
const offset = 280; // needs to be double of height / width to ensure its centered
spotlight.style.transform = `translate(${e.clientX - offset}px, ${e.clientY - offset}px)`;
});
});
// no spotlight for touchscreen devices (no cursor)
document.addEventListener("DOMContentLoaded", () => {
const isMobile = window.matchMedia('(pointer: coarse)').matches;
const spotlight = document.getElementById("spotlight");
if (isMobile) {
spotlight.classList.remove("md:opacity-30");
}
});
// for colour-changing text
window.addEventListener("scroll", () => {
const target = document.getElementById("contact");
const rect = target.getBoundingClientRect();
const element = document.getElementById("dynamic-text");
const offset = 0.4;
if (rect.top < window.innerHeight * offset) {
element.classList.remove("text-slate-400");
element.classList.add("text-slate-200");
} else {
element.classList.remove("text-slate-200");
element.classList.add("text-slate-400");
}
});
// change title in contact form when input is selected
function changeInputColour(titleId, inputId) {
const title = document.getElementById(titleId);
const input = document.getElementById(inputId);
input.addEventListener('focus', () => {
title.classList.remove('text-slate-400');
title.classList.add('text-slate-200');
input.classList.add('text-slate-200');
});
input.addEventListener('blur', () => {
title.classList.remove('text-slate-200');
title.classList.add('text-slate-400');
input.classList.remove('text-slate-200');
});
}
changeInputColour('email-title', 'email-input');
changeInputColour('subject-title', 'subject-input');
changeInputColour('msg-title', 'msg-input');
function interactiveNav() {
const sections = document.querySelectorAll("section");
const navlinks = document.querySelectorAll(".nav-link");
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// remove active
navlinks.forEach(link => link.classList.remove("active"));
// add active to current section
const id = entry.target.id;
const activeLink = document.querySelector(`.nav-link[href="#${id}"]`);
if (activeLink) activeLink.classList.add("active");
}
});
}, {
threshold: 0.7
});
sections.forEach(section => observer.observe(section));
}
interactiveNav();