implement age calculation + fix icons bug in english version

This commit is contained in:
Michi 2025-03-15 21:03:11 +01:00
parent be603e8e52
commit caca1c825e
7 changed files with 32 additions and 7 deletions

View file

@ -2,6 +2,7 @@
document.addEventListener('DOMContentLoaded', function(){
scrollTopVisibilityUpdate();
updateNavStyle();
calculateAge(".age");
});
window.addEventListener('scroll', function(){
@ -69,4 +70,22 @@ const observer = new IntersectionObserver(entries => {
});
});
observer.observe(document.querySelector('.contact-title-wrapper'));
observer.observe(document.querySelector('.contact-title-wrapper'));
// calculate age
function calculateAge(selector){
const obj = document.querySelector(selector);
const birthdate = obj.getAttribute("data-birthdate").split(",");
const birth = new Date(birthdate[2], birthdate[1] - 1, birthdate[0]);
const today = new Date();
let age = today.getFullYear() - birth.getFullYear();
const monthDiff = today.getMonth() - birth.getMonth();
const dayDiff = today.getDate() - birth.getDate();
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
age--;
}
obj.textContent = age;
}