<!DOCTYPE html> <html> <head> <style type="text/css"> body{ background: #333333; } div{ color:white; margin:auto; text-align:center; } </style> <script> function rebour_multiple(tempsFin, idRebour){ this.tempsFin=tempsFin; this.idRebour=document.getElementById(idRebour); this.inter=false; var that=this; this.inter=setInterval(function(){that.rebour()}, 1000); this.rebour() } rebour_multiple.prototype.rebour=function(){ var date1 = new Date().getTime(); var date2 = new Date(this.tempsFin).getTime(); if(date1>date2){ this.idRebour.firstChild.nodeValue ='fini' clearInterval(this.inter) } else{ var sec = (date2 - date1) / 1000; var n = 24 * 3600; var j = Math.floor (sec / n); var h = Math.floor ((sec - (j * n)) / 3600); var mn = Math.floor ((sec - ((j * n + h * 3600))) / 60); var sec = Math.floor (sec - ((j * n + h * 3600 + mn * 60))); j= j < 10 ? '0' + j : j; h= h < 10 ? '0' + h : h; mn= mn < 10 ? '0' + mn : mn; sec= sec < 10 ? '0' + sec : sec; if(j=="00" && h=="00" && mn=="00"){ this.idRebour.firstChild.nodeValue =sec+"s"; } else if(j=="00" && h=="00"){ this.idRebour.firstChild.nodeValue =mn +"m "+ sec+"s"; } else if(j=="00"){ this.idRebour.firstChild.nodeValue =h +"h "+ mn +"m "+ sec+"s"; } else{ this.idRebour.firstChild.nodeValue =j +"J "+ h +"h "+ mn +"m "+ sec+"s"; } } } function initcompteur(){ new rebour_multiple('09/10/2019 22:47:00',"compteur1"); new rebour_multiple('05/26/2019 12:55:20', "compteur2"); new rebour_multiple('08/02/2019 18:00:00', "compteur3"); new rebour_multiple('09/10/2019 22:47:00',"compteur4"); new rebour_multiple('012/18/2019 12:55:20', "compteur5"); new rebour_multiple('08/02/2019 18:00:00', "compteur6"); new rebour_multiple('09/10/2020 22:47:00',"compteur7"); new rebour_multiple('02/18/2019 12:55:20', "compteur8"); new rebour_multiple('04/05/2019 18:00:00', "compteur9"); } typeof window.addEventListener == 'undefined' ? window.attachEvent('onload', initcompteur) : window.addEventListener('load', initcompteur, false); </script> </head><body> <div id="compteur1">00:00:00</div> <br> <div id="compteur2">00:00:00</div> <br> <div id="compteur3">00:00:00</div> <br> <div id="compteur4">00:00:00</div> <br> <div id="compteur5">00:00:00</div> <br> <div id="compteur6">00:00:00</div> <br> <div id="compteur7">00:00:00</div> <br> <div id="compteur8">00:00:00</div> <br> <div id="compteur9">00:00:00</div> </body></html>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question