Last active
May 20, 2022 09:05
-
-
Save thecodeholic/d79999af014020d41cc5565d72f47c29 to your computer and use it in GitHub Desktop.
Fade-out HTML element every day until it fully disappears
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const el = document.querySelector('[style*=waska]') | |
const parent = el.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement; | |
const futureDate = new Date('2022-06-28 12:00:00') | |
const startDate = new Date('2022-05-19'); | |
const interval = setInterval(() => { | |
const nowDate = Date.now(); | |
const percent = Math.round((futureDate.getTime() - nowDate) * 100 / (futureDate.getTime() - startDate.getTime()) * 100) / 100 | |
console.log(percent) | |
if (percent <= 5) { | |
parent.remove(); | |
clearInterval(interval) | |
} else { | |
parent.style.opacity = percent/100; | |
} | |
}, 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment