@@ -66,7 +66,7 @@ export class CountUp {
6666
6767 constructor (
6868 target : string | HTMLElement | HTMLInputElement ,
69- private endVal : number ,
69+ private endVal ? : number ,
7070 public options ?: CountUpOptions
7171 ) {
7272 this . options = {
@@ -78,6 +78,9 @@ export class CountUp {
7878 this . easingFn = ( this . options . easingFn ) ?
7979 this . options . easingFn : this . easeOutExpo ;
8080
81+ this . el = ( typeof target === 'string' ) ? document . getElementById ( target ) : target ;
82+ endVal = endVal == null ? this . removeSeparators ( this . el . innerHTML ) : endVal ;
83+
8184 this . startVal = this . validateValue ( this . options . startVal ) ;
8285 this . frameVal = this . startVal ;
8386 this . endVal = this . validateValue ( endVal ) ;
@@ -88,7 +91,6 @@ export class CountUp {
8891 if ( this . options . separator === '' ) {
8992 this . options . useGrouping = false ;
9093 }
91- this . el = ( typeof target === 'string' ) ? document . getElementById ( target ) : target ;
9294 if ( this . el ) {
9395 this . printValue ( this . startVal ) ;
9496 } else {
@@ -335,4 +337,7 @@ export class CountUp {
335337 easeOutExpo = ( t : number , b : number , c : number , d : number ) : number =>
336338 c * ( - Math . pow ( 2 , - 10 * t / d ) + 1 ) * 1024 / 1023 + b ;
337339
340+ removeSeparators ( number : string ) : number {
341+ return parseFloat ( number . replace ( new RegExp ( this . options . separator , 'g' ) , '' ) )
342+ }
338343}
0 commit comments