setTimeout(function(){document.getElementById("mabulle").style.display="none"},6000)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script> function rebour_multiple(tempsFin, idRebour){ this.tempsFin=tempsFin; this.idRebour=document.getElementById(idRebour); this.rebour(); } rebour_multiple.prototype.rebour=function(){ var that=this; var date1 = new Date().getTime(); var date2 = new Date(this.tempsFin).getTime(); if(date1>date2){ this.idRebour.firstChild.nodeValue ='Temps restant : date passé' } 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; this.idRebour.firstChild.nodeValue = "Temps restant : " + j +"J "+ h +"H "+ mn +"Min "+ sec + "Sec "; } setTimeout(function(){that.rebour()}, 1000); } function initcompteur(){ new rebour_multiple('09/10/2015 22:47:00',"compteur1"); new rebour_multiple('02/18/2016 12:55:20', "compteur2"); new rebour_multiple('04/19/2017 23:00:00', "compteur3"); } typeof window.addEventListener == 'undefined' ? window.attachEvent('onload', initcompteur) : window.addEventListener('load', initcompteur, false); </script> </head><body> <span id="compteur1">00:00:00</span>; <br> <span id="compteur2">00:00:00</span>; <br> <span id="compteur3">00:00:00</span>; </body></html>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script> function rebour_multiple(tempsFin, idRebour){ this.tempsFin=new Date().getTime()+tempsFin*1000; this.idRebour=document.getElementById(idRebour); this.timer=""; this.rebour(); } rebour_multiple.prototype.rebour=function(){ var that=this; var date1 = new Date().getTime(); var date2 = this.tempsFin; if(date1>date2){ this.idRebour.firstChild.nodeValue ='perdu' } else{ var sec = (date2 - date1) / 1000; var mn = Math.floor (sec / 60); var sec = Math.floor (sec % 60); mn= mn < 10 ? '0' + mn : mn; sec= sec < 10 ? '0' + sec : sec; this.idRebour.firstChild.nodeValue = mn +"Min "+ sec + "Sec "; } this.timer=setTimeout(function(){that.rebour()}, 1000); } function touche(e){ if(e.keyCode==74){ clearTimeout(el_obj.timer) alert("gagne") document.getElementById('lien').style.display="block" } } var el_obj="" function initcompteur(){ el_obj=new rebour_multiple(120,"compteur1"); } typeof window.addEventListener == 'undefined' ? window.attachEvent('onload', initcompteur) : window.addEventListener('load', initcompteur, false); typeof window.addEventListener == 'undefined' ? window.attachEvent('onkeydown', touche) : window.addEventListener('keydown', touche, false); </script> </head><body> <span id="compteur1">00:00:00</span>; <a href="http://www.developpez.com/" id="lien" style="display:none">suivant</span>; </body></html>
7 nov. 2015 à 17:09
le setTimeout je le met à la suite dans la div?
7 nov. 2015 à 18:37
8 nov. 2015 à 00:42
Modifié par kazma le 8/11/2015 à 12:28
8 nov. 2015 à 21:19
Et par hasard vous ne sauriez pas comment faire un compte à rebours?