Skip to content

Commit

Permalink
Try to fix smooth scroll awaiting
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Oct 7, 2024
1 parent 2556196 commit 579ae67
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/survey-core/src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,29 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
public static ScrollIntoView(el: HTMLElement, scrollIntoViewOptions?: ScrollIntoViewOptions, doneCallback?: () => void): void {
el.scrollIntoView(scrollIntoViewOptions);
if (typeof doneCallback === "function") {
let currPageXOffset = window.pageXOffset;
let currPageYOffset = window.pageYOffset;
var scrollDone = setInterval(function () {
if (currPageXOffset == window.pageXOffset && currPageYOffset == window.pageYOffset) {
clearInterval(scrollDone);
let lastPos = null;
const checkPos = () => {
const newPos = el.getBoundingClientRect().top;
if (newPos === lastPos) {
doneCallback();
} else {
lastPos = newPos;
requestAnimationFrame(checkPos);
}
currPageXOffset = window.pageXOffset;
currPageYOffset = window.pageYOffset;
}, 25);
};
DomWindowHelper.requestAnimationFrame(checkPos);
// let currPageXOffset = window.pageXOffset;
// let currPageYOffset = window.pageYOffset;
// var scrollDone = setInterval(() => {
// DomWindowHelper.requestAnimationFrame(() => {
// if (currPageXOffset == window.pageXOffset && currPageYOffset == window.pageYOffset) {
// clearInterval(scrollDone);
// doneCallback();
// }
// currPageXOffset = window.pageXOffset;
// currPageYOffset = window.pageYOffset;
// });
// }, 25);
}
}
public static ScrollElementToTop(elementId: string, scrollIfVisible?: boolean, scrollIntoViewOptions?: ScrollIntoViewOptions, doneCallback?: () => void): boolean {
Expand Down

0 comments on commit 579ae67

Please sign in to comment.