-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
162 lines (134 loc) · 4.96 KB
/
script.js
File metadata and controls
162 lines (134 loc) · 4.96 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
setInterval(function () {
document.querySelector("#timeElement").innerHTML = new Date().toLocaleString();
}, 1000);
// making the window element draggable:
dragElement(document.getElementById("welcome"));
// function called `dragElement` that makes an HTML element draggable.
function dragElement(element, header) {
// set up variables to keep track of the element's position.
var initialX = 0;
var initialY = 0;
var currentX = 0;
var currentY = 0;
var dragTarget = header || element;
dragTarget.onmousedown = startDragging;
// define the `startDragging` function to capture the initial mouse position and set up event listeners.
function startDragging(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup.
initialX = e.clientX;
initialY = e.clientY;
// set up event listeners for mouse movement (`dragElement`) and mouse button release (`stopDragging`).
document.onmouseup = stopDragging;
document.onmousemove = elementDrag;
}
// define the `elementDrag` function to calculate the new position of the element based on mouse movement.
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position.
currentX = initialX - e.clientX;
currentY = initialY - e.clientY;
initialX = e.clientX;
initialY = e.clientY;
// update the element's new position by modifying its `top` and `left` CSS properties.
element.style.top = (element.offsetTop - currentY) + "px";
element.style.left = (element.offsetLeft - currentX) + "px";
}
// define the `stopDragging` function to stop tracking mouse movement by removing the event listeners.
function stopDragging() {
document.onmouseup = null;
document.onmousemove = null;
}
}
// for the welcome window
var welcomeScreen = document.querySelector("#welcome");
var welcomeScreenClose = document.querySelector("#welcomeclose");
welcomeScreenClose.addEventListener("click", function () {
closeWindow(welcomeScreen);
});
function closeWindow(element) {
element.style.display = "none";
}
// Function to open the window (if needed)
function openWindow(element) {
element.style.display = "flex";
}
// for the about window
var aboutSection = document.querySelector("#about");
var aboutSectionClose = document.querySelector("#aboutclose");
dragElement(aboutSection);
aboutSectionClose.addEventListener("click", function () {
closeWindow(aboutSection);
});
//for the interest window
var interestSection = document.querySelector("#interest");
var interestSectionClose = document.querySelector("#interestclose");
dragElement(interestSection);
interestSectionClose.addEventListener("click", function () {
closeWindow(interestSection);
});
// for the contact window
var contactSection = document.querySelector("#contact");
var contactSectionClose = document.querySelector("#contactclose");
dragElement(contactSection);
contactSectionClose.addEventListener("click", function () {
closeWindow(contactSection);
});
// for the image window
var imageSection = document.querySelector("#image");
var imageSectionClose = document.querySelector("#imageclose");
dragElement(imageSection);
imageSectionClose.addEventListener("click", function () {
closeWindow(imageSection);
});
// for the tunes window
var tunesSection = document.querySelector("#tunes");
var tunesSectionClose = document.querySelector("#tunesclose");
dragElement(tunesSection);
tunesSectionClose.addEventListener("click", function () {
closeWindow(tunesSection);
});
let topZ = 10; // initial z-index
document.querySelectorAll('.window').forEach(win => {
win.addEventListener('mousedown', () => {
topZ++;
win.style.zIndex = topZ;
});
});
const poemLines = [
"windows closed",
"pixels fade—",
"but thanks for staying",
"and pressing play.",
];
function typePoem(lines, el, lineIdx = 0, charIdx = 0) {
if (lineIdx >= lines.length) return;
if (!el.textContent) el.textContent = '';
const line = lines[lineIdx];
if (charIdx < line.length) {
el.textContent += line.charAt(charIdx);
setTimeout(() => typePoem(lines, el, lineIdx, charIdx + 1), 60);
} else {
el.textContent += '\n';
setTimeout(() => typePoem(lines, el, lineIdx + 1, 0), 300);
}
}
function showPoemEgg() {
const poemEl = document.getElementById('poemEgg');
poemEl.style.display = 'block';
poemEl.textContent = '';
typePoem(poemLines, poemEl);
}
function checkAllClosedAndShowPoem() {
const windows = document.querySelectorAll('.window');
const allClosed = Array.from(windows).every(w => w.style.display === 'none');
if (allClosed) showPoemEgg();
}
document.querySelectorAll('.closebutton').forEach(btn => {
btn.addEventListener('click', () => {
btn.closest('.window').style.display = 'none';
checkAllClosedAndShowPoem();
});
});