server/assets/production/scripts/countdown.js

1 line
No EOL
828 B
JavaScript

const countdown=document.getElementById("countdown"),counter=document.getElementById("counter"),daysContainer=document.getElementById("days"),hoursContainer=document.getElementById("hours"),minutesContainer=document.getElementById("minutes"),secondsContainer=document.getElementById("seconds");let target=new Date("2020-09-04 15:00:00"),shown=!1;function render(){let e=new Date,t=target-e;var n=Math.floor(t/864e5),o=Math.floor(t%864e5/36e5),r=Math.floor(t%36e5/6e4),d=Math.floor(t%6e4/1e3);n=String(n).length>=2?n:"0"+n,o=String(o).length>=2?o:"0"+o,r=String(r).length>=2?r:"0"+r,d=String(d).length>=2?d:"0"+d,daysContainer.textContent=n,hoursContainer.textContent=o,minutesContainer.textContent=r,secondsContainer.textContent=d,shown||setTimeout(()=>{countdown.style.opacity=1,shown=!0},300)}render(),setInterval(render,1e3);