-
Notifications
You must be signed in to change notification settings - Fork 112
refactor: requestAnimationFrame #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,11 +54,11 @@ export class PageScrollService { | |
| pageScrollInstance.detachInterruptListeners(); | ||
| } | ||
|
|
||
| if (pageScrollInstance.timer) { | ||
| if (pageScrollInstance.requestFrameId) { | ||
| // Clear/Stop the timer | ||
| clearInterval(pageScrollInstance.timer); | ||
| window.cancelAnimationFrame(pageScrollInstance.requestFrameId) | ||
| // Clear the reference to this timer | ||
| pageScrollInstance.timer = undefined; | ||
| pageScrollInstance.requestFrameId = null; | ||
| pageScrollInstance.fireEvent(!interrupted); | ||
|
|
||
| return true; | ||
|
|
@@ -198,7 +198,14 @@ export class PageScrollService { | |
| // .. and calculate the end time (when we need to finish at last) | ||
| pageScrollInstance.endTime = pageScrollInstance.startTime + pageScrollInstance.executionDuration; | ||
|
|
||
| pageScrollInstance.timer = setInterval((instance: PageScrollInstance) => { | ||
| pageScrollInstance.requestFrameId = window.requestAnimationFrame(this.updateScrollPostion(pageScrollInstance)) | ||
|
|
||
| // Register the instance as running one | ||
| this.runningInstances.push(pageScrollInstance); | ||
| } | ||
|
|
||
| public updateScrollPostion(instance: PageScrollInstance){ | ||
| return ()=>{ | ||
| // Take the current time | ||
| const currentTime: number = new Date().getTime(); | ||
|
|
||
|
|
@@ -231,12 +238,10 @@ export class PageScrollService { | |
| // (otherwise the event might arrive at "too early") | ||
| if (stopNow) { | ||
| this.stopInternal(false, instance); | ||
| } else{ | ||
| window.requestAnimationFrame(this.updateScrollPostion(instance)) | ||
| } | ||
|
|
||
| }, this.config._interval, pageScrollInstance); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the config
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have deleted everything related with |
||
|
|
||
| // Register the instance as running one | ||
| this.runningInstances.push(pageScrollInstance); | ||
| } | ||
| } | ||
|
|
||
| public scroll(options: PageScrollOptions): void { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global
windowobject shouldn't be access directly, rather the little bit more complicated angular way viadocumentobject, that we already got hold of at the pageScrollInstance confighttps://stackoverflow.com/a/50023378/2225619 , https://stackoverflow.com/a/52620181/2225619)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I changed it, now I am using
pageScrollInstance.pageScrollOptions.document.defalutViewinstead ofwindow