-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
194 lines (162 loc) · 8.57 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
183
184
185
186
187
188
189
190
191
192
193
194
//below is for my bee that follows the curser
document.addEventListener('mousemove', (event) => {
// get the main element
const mainElement = document.querySelector('main');
// calculate the position of the mouse relative to the viewport
const xPercent = (event.clientX / window.innerWidth) * 100;
const yPercent = (event.clientY / window.innerHeight) * 100;
// update the background position to follow the cursor
mainElement.style.backgroundPosition = `${xPercent}% ${yPercent}%`;
});
//---------------------------------------------------------------------
//below is for the main section two divs appearing slowly after eachother
document.addEventListener('DOMContentLoaded', () => {
// selects elements
const textContent1 = document.querySelector('.text-content1');
const textContent2 = document.querySelector('.text-content2');
// shows element 1 after 1 second
setTimeout(() => {
textContent1.classList.add('visible');
}, 1000); // 1000ms = 1 second
// show element 2 after 2 seconds
setTimeout(() => {
textContent2.classList.add('visible');
}, 2000); // 2000ms = 2 seconds
});
// ------------------------------------------------------------------
// below is the code for changing from light mode to dark mode
document.getElementById("toggle-colors").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("toggle-colors").textContent); // debug statement to check what the content is
document.body.classList.toggle("invert-colors");
const button = document.getElementById("toggle-colors"); // these 3 lines are changing the moon to sun & back
button.textContent = button.textContent === "☽" ? "☼" : "☽";
console.log("After toggle:", button.textContent); // debug statement to check what the content is
});
// ------------------------------------------------------------------
// below is the code for the contact form in main element
const main = document.getElementById('column1');
const originalContent = column1.innerHTML; // save the original content when the page loads
// function to reapply animations to the main sections
function reapplyAnimations() {
const textContent1 = main.querySelector('.text-content1');
const textContent2 = main.querySelector('.text-content2');
if (textContent1) {
textContent1.classList.remove('visible'); // reset the animation state
textContent1.classList.add('hidden'); // start hidden
setTimeout(() => {
textContent1.classList.add('visible'); // trigger the animation
}, 1000); // 1000ms = 1 second
}
if (textContent2) {
textContent2.classList.remove('visible'); // reset animation
textContent2.classList.add('hidden'); // start hidden
setTimeout(() => {
textContent2.classList.add('visible'); // trigger the animation
}, 2000); // 2000ms = 2 seconds
}
}
// show the contact form when 'show-contact-form' aka contact in nav is clicked
document.getElementById('show-contact-form').addEventListener('click', () => {
const contactForm = document.getElementById('contact-form');
const column1 = document.getElementById('column1');
const column2 = document.getElementById('column2');
const column3 = document.getElementById('column3');
if (!contactForm || !column1 || !column2 || !column3) {
console.error("elements not found, beep boop");
return;
}
// clear content and show the contact form
column1.innerHTML = ''; // clear content of column1
column2.style.display = 'none'; // hide column2
column3.style.display = 'none'; // hide column3
contactForm.style.display = 'block'; // make form visible
column1.appendChild(contactForm); // add form to column1
});
// reset to original content when 'home-button' clicked
document.getElementById('home-button').addEventListener('click', () => {
const column1 = document.getElementById('column1');
const column2 = document.getElementById('column2');
const column3 = document.getElementById('column3');
const contactForm = document.getElementById('contact-form');
if (!column1 || !column2 || !column3 || !contactForm) {
console.error("One or more elements not found");
return;
}
// reset original content and show both columns
column1.innerHTML = originalContent; // reset column1
column2.style.display = 'block'; // show column2
column3.style.display = 'block'; // show column3
contactForm.style.display = 'none'; // hide contact form
reapplyAnimations(); // reapply animations column1 content
});
//------------------------------------------------------------------
//below is advent calendar javascript
document.getElementById("present1").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present1").textContent);
const button = document.getElementById("present1");
button.textContent = button.textContent === "🎁" ? "🕊️" : "🎁";
console.log("After toggle:", button.textContent);
});
//-----------------
document.getElementById("present2").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present2").textContent);
const button = document.getElementById("present2");
button.textContent = button.textContent === "🎁" ? "🍷" : "🎁";
console.log("After toggle:", button.textContent);
});
//-----------------
document.getElementById("present3").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present3").textContent);
const button = document.getElementById("present3");
button.textContent = button.textContent === "🎁" ? "🦃" : "🎁";
console.log("After toggle:", button.textContent);
});
//-----------------
document.getElementById("present4").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present4").textContent);
const button = document.getElementById("present4");
button.textContent = button.textContent === "🎁" ? "❄️" : "🎁";
console.log("After toggle:", button.textContent);
});
//-----------------
document.getElementById("present5").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present5").textContent);
const button = document.getElementById("present5");
button.textContent = button.textContent === "🎁" ? "☃️" : "🎁";
console.log("After toggle:", button.textContent);
});
//------------------
document.getElementById("present6").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present6").textContent);
const button = document.getElementById("present6");
button.textContent = button.textContent === "🎁" ? "🌟" : "🎁";
console.log("After toggle:", button.textContent);
});
//------------------
document.getElementById("present7").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present7").textContent);
const button = document.getElementById("present7");
button.textContent = button.textContent === "🎁" ? "🔔" : "🎁";
console.log("After toggle:", button.textContent);
});
//------------------
document.getElementById("present8").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present8").textContent);
const button = document.getElementById("present8");
button.textContent = button.textContent === "🎁" ? "🍪" : "🎁";
console.log("After toggle:", button.textContent);
});
//----------------
document.getElementById("present9").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present9").textContent);
const button = document.getElementById("present9");
button.textContent = button.textContent === "🎁" ? "🦌" : "🎁";
console.log("After toggle:", button.textContent);
});
//-----------------
document.getElementById("present10").addEventListener("click", () => {
console.log("Before toggle:", document.getElementById("present10").textContent);
const button = document.getElementById("present10");
button.textContent = button.textContent === "🎁" ? "🎄" : "🎁";
console.log("After toggle:", button.textContent);
});