Skip to content

Instantly share code, notes, and snippets.

@thecodeholic
Last active May 20, 2022 09:05
Show Gist options
  • Save thecodeholic/d79999af014020d41cc5565d72f47c29 to your computer and use it in GitHub Desktop.
Save thecodeholic/d79999af014020d41cc5565d72f47c29 to your computer and use it in GitHub Desktop.
Fade-out HTML element every day until it fully disappears
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