@@ -54,11 +54,11 @@ export class PageScrollService {
5454 pageScrollInstance . detachInterruptListeners ( ) ;
5555 }
5656
57- if ( pageScrollInstance . timer ) {
57+ if ( pageScrollInstance . requestFrameId ) {
5858 // Clear/Stop the timer
59- clearInterval ( pageScrollInstance . timer ) ;
59+ window . cancelAnimationFrame ( pageScrollInstance . requestFrameId )
6060 // Clear the reference to this timer
61- pageScrollInstance . timer = undefined ;
61+ pageScrollInstance . requestFrameId = null ;
6262 pageScrollInstance . fireEvent ( ! interrupted ) ;
6363
6464 return true ;
@@ -198,7 +198,14 @@ export class PageScrollService {
198198 // .. and calculate the end time (when we need to finish at last)
199199 pageScrollInstance . endTime = pageScrollInstance . startTime + pageScrollInstance . executionDuration ;
200200
201- pageScrollInstance . timer = setInterval ( ( instance : PageScrollInstance ) => {
201+ pageScrollInstance . requestFrameId = window . requestAnimationFrame ( this . updateScrollPostion ( pageScrollInstance ) )
202+
203+ // Register the instance as running one
204+ this . runningInstances . push ( pageScrollInstance ) ;
205+ }
206+
207+ public updateScrollPostion ( instance : PageScrollInstance ) {
208+ return ( ) => {
202209 // Take the current time
203210 const currentTime : number = new Date ( ) . getTime ( ) ;
204211
@@ -231,12 +238,10 @@ export class PageScrollService {
231238 // (otherwise the event might arrive at "too early")
232239 if ( stopNow ) {
233240 this . stopInternal ( false , instance ) ;
241+ } else {
242+ window . requestAnimationFrame ( this . updateScrollPostion ( instance ) )
234243 }
235-
236- } , this . config . _interval , pageScrollInstance ) ;
237-
238- // Register the instance as running one
239- this . runningInstances . push ( pageScrollInstance ) ;
244+ }
240245 }
241246
242247 public scroll ( options : PageScrollOptions ) : void {
0 commit comments