mirror of
https://github.com/michivonah/website-v3.git
synced 2025-12-22 21:36:28 +01:00
implement age calculation + fix icons bug in english version
This commit is contained in:
parent
be603e8e52
commit
caca1c825e
7 changed files with 32 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue