FIX: prevents multiple jumps to happen with LockOn (#8460)
This commit is contained in:
parent
46d8fd3831
commit
c5140ef3fb
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue