-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
107 lines (87 loc) · 2.71 KB
/
app.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
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
// console.log(entry)
if(entry.isIntersecting) {
entry.target.classList.add('show');
} else {
entry.target.classList.remove('show');
}
})
})
const hiddenElements = document.querySelectorAll('.hidden');
hiddenElements.forEach((elem) => observer.observe(elem))
const observerCert = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
// console.log(entry)
if (entry.isIntersecting) {
entry.target.classList.add('cert-show');
} else {
entry.target.classList.remove('cert-show');
}
})
})
const hiddenCerts = document.querySelectorAll('.cert-hidden');
hiddenCerts.forEach((elem) => observerCert.observe(elem))
var age, daysBetweenDates;
daysBetweenDates = function (d1, d2) {
var diffDays, oneDay;
oneDay = 24 * 60 * 60 * 1000;
diffDays = (d2 - Date.parse(d1)) / oneDay;
return diffDays;
};
age = function () {
var birthDate = new Date('Feb 7, 2009 00:00:00');
var currentDate = new Date();
var years = daysBetweenDates(birthDate, currentDate) / 365.25; // Consider leap years
document.getElementById('myAge').innerText = (years.toFixed(8));
};
setInterval(age, 1200);
document.getElementById("year").innerHTML = new Date().getFullYear();
const carouselText = [
{ text: "Hu Kaixiang", color: "orange" },
{ text: "胡凱翔", color: "orange" }
];
document.addEventListener("DOMContentLoaded", async function () {
carousel(carouselText, "#typing-container-text");
});
async function typeSentence(sentence, eleRef, delay = 100) {
const letters = sentence.split("");
let i = 0;
while (i < letters.length) {
await waitForMs(delay);
document.querySelector(eleRef).innerHTML += letters[i];
i++;
}
return;
}
async function deleteSentence(eleRef) {
const sentence = document.querySelector(eleRef).innerHTML;
const letters = sentence.split("");
let i = 0;
while (letters.length > 0) {
await waitForMs(100);
letters.pop();
document.querySelector(eleRef).innerHTML = letters.join("");
}
}
async function carousel(carouselList, eleRef) {
var i = 0;
while (true) {
updateFontColor(eleRef, carouselList[i].color);
await typeSentence(carouselList[i].text, eleRef);
await waitForMs(1500);
await deleteSentence(eleRef);
await waitForMs(500);
i++;
if (i >= carouselList.length) { i = 0; }
}
}
function updateFontColor(eleRef, color) {
document.querySelector(eleRef).style.color = color;
}
function waitForMs(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// particlesJS.load('particles-js', 'assets/particles.json', function () {
// console.log('callback - particles.js config loaded');
// });