FIX: prevents multiple jumps to happen with LockOn (#8460)

This commit is contained in:
Joffrey JAFFEUX 2019-12-04 16:45:23 +01:00 committed by GitHub
parent 46d8fd3831
commit c5140ef3fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

View File

@ -51,23 +51,25 @@ export default class LockOn {
lock() { lock() {
const startedAt = new Date().getTime(); const startedAt = new Date().getTime();
let previousTop = this.elementTop(); let previousTop = this.elementTop();
previousTop && $(window).scrollTop(previousTop);
const interval = setInterval(() => { const interval = setInterval(() => {
if (!previousTop) { const elementTop = this.elementTop();
previousTop = this.elementTop(); if (!previousTop && !elementTop) {
previousTop && $(window).scrollTop(previousTop); // we can't find the element yet, wait a little bit more
} else { return;
const top = Math.max(0, this.elementTop()); }
const scrollTop = $(window).scrollTop();
if (typeof top === "undefined" || isNaN(top)) { const top = Math.max(0, elementTop);
return this.clearLock(interval); const scrollTop = $(window).scrollTop();
}
if (!within(4, top, previousTop) || !within(4, scrollTop, top)) { if (typeof top === "undefined" || isNaN(top)) {
$(window).scrollTop(top); return this.clearLock(interval);
previousTop = top; }
}
if (!within(4, top, previousTop) || !within(4, scrollTop, top)) {
$(window).scrollTop(top);
previousTop = top;
} }
// Commit suicide after a little while // Commit suicide after a little while