File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11calc ( "sec" , getSec ) ;
22calc ( "min" , getMin ) ;
33var intSec = setInterval ( 'calc("sec", getSec)' , 1000 ) ;
4+ var intMin ;
45
56function calc ( type , func ) {
67 $ ( '.counter.' + type + ' .to' )
@@ -10,48 +11,52 @@ function calc(type, func) {
1011 . removeClass ( 'hide' )
1112 . addClass ( 'n' )
1213 . find ( 'span:not(.shadow)' ) . each ( function ( i , el ) {
13- $ ( el ) . text ( func ( true ) ) ;
14- } ) ;
14+ $ ( el ) . text ( func ( true ) ) ;
15+ } ) ;
1516 $ ( '.counter.' + type + ' .from:not(.n)' )
1617 . addClass ( 'hide' )
1718 . addClass ( 'to' )
1819 . removeClass ( 'from' )
1920 . removeClass ( 'hide' )
20- . find ( 'span:not(.shadow)' ) . each ( function ( i , el ) {
21- $ ( el ) . text ( func ( false ) ) ;
22- } ) ;
21+ . find ( 'span:not(.shadow)' ) . each ( function ( i , el ) {
22+ $ ( el ) . text ( func ( false ) ) ;
23+ } ) ;
2324 $ ( '.counter.' + type + ' .n' ) . removeClass ( 'n' ) ;
2425}
2526
2627
2728function getSec ( next ) {
2829 var d = new Date ( ) ;
2930 var sec = 60 - d . getSeconds ( ) ;
31+
3032 if ( next ) {
3133 sec -- ;
3234 if ( sec < 0 ) {
3335 sec = 59 ;
3436 }
3537 } else if ( sec == 60 ) {
3638 sec = 0 ;
37- calc ( 'min' , getMin ) ;
39+ if ( intMin == undefined ) {
40+ calc ( "min" , getMin ) ;
41+ intMin = setInterval ( 'calc("min", getMin)' , 60000 ) ;
42+ }
3843 }
3944
4045 return ( sec < 10 ? '0' + sec : sec ) ;
4146}
4247
4348function getMin ( next ) {
4449 var d = new Date ( ) ;
45- var sec = 60 - d . getMinutes ( ) ;
50+ var min = 60 - d . getMinutes ( ) ;
4651 if ( next ) {
47- sec -- ;
48- if ( sec < 0 ) {
49- sec = 59 ;
52+ min -- ;
53+ if ( min < 0 ) {
54+ min = 59 ;
5055 }
51- } else if ( sec == 60 ) {
52- sec = 0 ;
56+ } else if ( min == 60 ) {
57+ min = 0 ;
5358// calcMin();
5459 }
5560
56- return ( sec < 10 ? '0' + sec : sec ) ;
61+ return ( min < 10 ? '0' + min : min ) ;
5762}
You can’t perform that action at this time.
0 commit comments