1- const second = 1000 ,
2- minute = second * 60 ,
3- hour = minute * 60 ,
4- day = hour * 24 ;
1+ function initCountDown ( countDown ) {
2+ const second = 1000 ,
3+ minute = second * 60 ,
4+ hour = minute * 60 ,
5+ day = hour * 24 ;
6+ x = setInterval ( function ( ) {
57
6- let countDown = new Date ( 'Apr 17, 2020 11:59:59' ) . getTime ( ) ,
7- x = setInterval ( function ( ) {
8+ let now = new Date ( ) . getTime ( ) ,
9+ distance = countDown - now ;
810
9- let now = new Date ( ) . getTime ( ) ,
10- distance = countDown - now ;
11+ document . getElementsByClassName ( 'days' ) [ 0 ] . innerText = Math . floor ( distance / ( day ) ) ,
12+ document . getElementsByClassName ( 'days' ) [ 1 ] . innerText = Math . floor ( distance / ( day ) ) ,
13+ document . getElementsByClassName ( 'hours' ) [ 0 ] . innerText = Math . floor ( ( distance % ( day ) ) / ( hour ) ) ,
14+ document . getElementsByClassName ( 'hours' ) [ 1 ] . innerText = Math . floor ( ( distance % ( day ) ) / ( hour ) ) ,
15+ document . getElementsByClassName ( 'minutes' ) [ 0 ] . innerText = Math . floor ( ( distance % ( hour ) ) / ( minute ) ) ,
16+ document . getElementsByClassName ( 'minutes' ) [ 1 ] . innerText = Math . floor ( ( distance % ( hour ) ) / ( minute ) ) ,
17+ document . getElementsByClassName ( 'seconds' ) [ 0 ] . innerText = Math . floor ( ( distance % ( minute ) ) / second ) ,
18+ document . getElementsByClassName ( 'seconds' ) [ 1 ] . innerText = Math . floor ( ( distance % ( minute ) ) / second ) ;
1119
12- document . getElementsByClassName ( 'days' ) [ 0 ] . innerText = Math . floor ( distance / ( day ) ) ,
13- document . getElementsByClassName ( 'days' ) [ 1 ] . innerText = Math . floor ( distance / ( day ) ) ,
14- document . getElementsByClassName ( 'hours' ) [ 0 ] . innerText = Math . floor ( ( distance % ( day ) ) / ( hour ) ) ,
15- document . getElementsByClassName ( 'hours' ) [ 1 ] . innerText = Math . floor ( ( distance % ( day ) ) / ( hour ) ) ,
16- document . getElementsByClassName ( 'minutes' ) [ 0 ] . innerText = Math . floor ( ( distance % ( hour ) ) / ( minute ) ) ,
17- document . getElementsByClassName ( 'minutes' ) [ 1 ] . innerText = Math . floor ( ( distance % ( hour ) ) / ( minute ) ) ,
18- document . getElementsByClassName ( 'seconds' ) [ 0 ] . innerText = Math . floor ( ( distance % ( minute ) ) / second ) ,
19- document . getElementsByClassName ( 'seconds' ) [ 1 ] . innerText = Math . floor ( ( distance % ( minute ) ) / second ) ;
20+ if ( distance < 0 ) {
21+ clearInterval ( x ) ;
22+ 'Tempo esgotado!' ;
23+ }
2024
21- if ( distance < 0 ) {
22- clearInterval ( x ) ;
23- 'Tempo esgotado!' ;
24- }
25-
26- } , second )
25+ } , second )
26+ }
0 commit comments