@@ -15,7 +15,7 @@ var CountUp = /** @class */ (function () {
1515 var _this = this ;
1616 this . endVal = endVal ;
1717 this . options = options ;
18- this . version = '2.3.1 ' ;
18+ this . version = '2.3.2 ' ;
1919 this . defaults = {
2020 startVal : 0 ,
2121 decimalPlaces : 0 ,
@@ -55,20 +55,11 @@ var CountUp = /** @class */ (function () {
5555 }
5656 }
5757 else {
58- if ( _this . countDown ) {
59- _this . frameVal = _this . startVal - ( ( _this . startVal - _this . endVal ) * ( progress / _this . duration ) ) ;
60- }
61- else {
62- _this . frameVal = _this . startVal + ( _this . endVal - _this . startVal ) * ( progress / _this . duration ) ;
63- }
58+ _this . frameVal = _this . startVal + ( _this . endVal - _this . startVal ) * ( progress / _this . duration ) ;
6459 }
6560 // don't go past endVal since progress can exceed duration in the last frame
66- if ( _this . countDown ) {
67- _this . frameVal = ( _this . frameVal < _this . endVal ) ? _this . endVal : _this . frameVal ;
68- }
69- else {
70- _this . frameVal = ( _this . frameVal > _this . endVal ) ? _this . endVal : _this . frameVal ;
71- }
61+ var wentPast = _this . countDown ? _this . frameVal < _this . endVal : _this . frameVal > _this . endVal ;
62+ _this . frameVal = wentPast ? _this . endVal : _this . frameVal ;
7263 // decimal
7364 _this . frameVal = Number ( _this . frameVal . toFixed ( _this . options . decimalPlaces ) ) ;
7465 // format and print value
@@ -113,6 +104,7 @@ var CountUp = /** @class */ (function () {
113104 }
114105 return neg + _this . options . prefix + x1 + x2 + _this . options . suffix ;
115106 } ;
107+ // t: current time, b: beginning value, c: change in value, d: duration
116108 this . easeOutExpo = function ( t , b , c , d ) {
117109 return c * ( - Math . pow ( 2 , - 10 * t / d ) + 1 ) * 1024 / 1023 + b ;
118110 } ;
@@ -141,7 +133,7 @@ var CountUp = /** @class */ (function () {
141133 // scroll spy
142134 if ( typeof window !== 'undefined' && this . options . enableScrollSpy ) {
143135 if ( ! this . error ) {
144- // set up global array of onscroll functions
136+ // set up global array of onscroll functions to handle multiple instances
145137 window [ 'onScrollFns' ] = window [ 'onScrollFns' ] || [ ] ;
146138 window [ 'onScrollFns' ] . push ( function ( ) { return _this . handleScroll ( _this ) ; } ) ;
147139 window . onscroll = function ( ) {
@@ -172,12 +164,17 @@ var CountUp = /** @class */ (function () {
172164 self . reset ( ) ;
173165 }
174166 } ;
175- // determines where easing starts and whether to count down or up
167+ /**
168+ * Smart easing works by breaking the animation into 2 parts, the second part being the
169+ * smartEasingAmount and first part being the total amount minus the smartEasingAmount. It works
170+ * by disabling easing for the first part and enabling it on the second part. It is used if
171+ * usingEasing is true and the total animation amount exceeds the smartEasingThreshold.
172+ */
176173 CountUp . prototype . determineDirectionAndSmartEasing = function ( ) {
177174 var end = ( this . finalEndVal ) ? this . finalEndVal : this . endVal ;
178175 this . countDown = ( this . startVal > end ) ;
179176 var animateAmount = end - this . startVal ;
180- if ( Math . abs ( animateAmount ) > this . options . smartEasingThreshold ) {
177+ if ( Math . abs ( animateAmount ) > this . options . smartEasingThreshold && this . options . useEasing ) {
181178 this . finalEndVal = end ;
182179 var up = ( this . countDown ) ? 1 : - 1 ;
183180 this . endVal = end + ( up * this . options . smartEasingAmount ) ;
@@ -187,7 +184,8 @@ var CountUp = /** @class */ (function () {
187184 this . endVal = end ;
188185 this . finalEndVal = null ;
189186 }
190- if ( this . finalEndVal ) {
187+ if ( this . finalEndVal !== null ) {
188+ // setting finalEndVal indicates smart easing
191189 this . useEasing = false ;
192190 }
193191 else {
@@ -241,7 +239,7 @@ var CountUp = /** @class */ (function () {
241239 return ;
242240 }
243241 this . startVal = this . frameVal ;
244- if ( ! this . finalEndVal ) {
242+ if ( this . finalEndVal == null ) {
245243 this . resetDuration ( ) ;
246244 }
247245 this . finalEndVal = null ;
0 commit comments