/** * countdown.js * * JavaScript Countdown Library * * @url https://f.malte70.de/silvester-countdown/ */ var Countdown = { deadline: new Date(), message: null, clockStyle: 0, clock: null, init: function(id, deadline, message, clockStyle=0) { this.clock = document.getElementById(id); this.deadline = deadline; this.message = message; this.clockStyle = clockStyle; this.update(); this.timeinterval = setInterval(() => {this.update();}, 100); }, getTimeRemaining: function() { const total = Date.parse(this.deadline) - Date.parse(new Date()); const seconds = Math.floor( (total/1000) % 60 ); const minutes = Math.floor( (total/1000/60) % 60 ); const hours = Math.floor( (total/(1000*60*60)) % 24 ); const days = Math.floor( total/(1000*60*60*24) ); return { total, days, hours, minutes, seconds }; }, update: function() { const t = this.getTimeRemaining(); if (this.clockStyle == 0) { this.clock.innerHTML = 'Tage: ' + t.days + '
\n' + 'Stunden: '+ t.hours + '
\n' + 'Minuten: ' + t.minutes + '
\n' + 'Sekunden: ' + t.seconds; } else { this.clock.style.textAlign = "center"; this.clock.innerHTML = (t.hours<10 ? "0" : "") + t.hours + ":" + (t.minutes<10 ? "0" : "") + t.minutes + ":" + (t.seconds<10 ? "0" : "") + t.seconds; //this.clock.innerHTML += "." + (t.total % 1000)/10; } if (t.total <= 1000) { //if (t.total <= 200) { clearInterval(this.timeinterval); //document.querySelector("h1").innerHTML = " "; this.clock.innerHTML = this.message; } } }