-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (66 loc) · 2.19 KB
/
script.js
File metadata and controls
79 lines (66 loc) · 2.19 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
document.addEventListener('DOMContentLoaded', function () {
const modal = document.getElementById('modal');
const modalBody = document.getElementById('modal-body');
const buttons = document.querySelectorAll('button[data-target]');
const closeBtn = document.getElementsByClassName('close')[0];
const h1Text = `Hi. I'm<br> Sophia Banda.`;
let i = 0;
window.addEventListener('load', function typeEffect() {
if (i < h1Text.length) {
const currentChar = h1Text.charAt(i);
if (currentChar === '<') {
const brTag = h1Text.substring(i, i + 4);
if (brTag === '<br>') {
this.document.querySelector('h1').innerHTML += '<br>';
i += 4;
}
} else {
this.document.querySelector('h1').innerHTML += currentChar;
i++;
}
this.setTimeout(typeEffect, 100);
}
});
buttons.forEach((button) => {
button.addEventListener('click', function () {
const targetId = this.getAttribute('data-target');
const targetContent = document.getElementById(targetId).innerHTML;
modalBody.innerHTML = '';
modalBody.innerHTML = targetContent;
if (targetId === 'work') {
modalBody.classList.add('scrollable-section');
} else {
modalBody.classList.remove('scrollable-section');
}
if (modalBody.innerHTML.trim() !== '') {
modal.style.display = 'flex';
}
});
});
closeBtn.addEventListener('click', function () {
modal.style.display = 'none';
});
window.addEventListener('click', function (event) {
if (event.target == modal) {
modal.style.display = 'none';
}
});
});
window.addEventListener(
'mousemove',
function (e) {
const arr = [1, 0.9, 0.8, 0.5, 0.2];
arr.forEach(function (i) {
var x = (1 - i) * 75;
var star = document.createElement('div');
star.className = 'star';
star.style.top = e.pageY + Math.round(Math.random() * x - x / 2) + 'px';
star.style.left = e.pageX + Math.round(Math.random() * x - x / 2) + 'px';
document.body.appendChild(star);
window.setTimeout(function () {
document.body.removeChild(star);
}, Math.round(Math.random() * i * 600));
});
},
false
);