mirror of
https://github.com/McShelby/hugo-theme-relearn
synced 2025-04-30 15:08:46 +08:00
scroll: fix position saving #1014
throttling wasn't working at all, should be debounce to get the last position
This commit is contained in:
parent
0dd98363fb
commit
85824e217f
@ -1 +1 @@
|
|||||||
7.3.2+de59e6700a230cecc75cebb1b225fe189f0189e7
|
7.3.2+0dd98363fbc04746c77cd13539a0d1b3f1a9de8e
|
@ -62,14 +62,11 @@ function adjustContentWidth() {
|
|||||||
elc.style[dir_padding_end] = '' + end + 'px';
|
elc.style[dir_padding_end] = '' + end + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
function throttle(func, limit) {
|
let debounceTimeout;
|
||||||
let inThrottle;
|
function debounce(func, delay) {
|
||||||
return function (...args) {
|
return function (...args) {
|
||||||
if (!inThrottle) {
|
clearTimeout(debounceTimeout);
|
||||||
func.apply(this, args);
|
debounceTimeout = setTimeout(() => func.apply(this, args), delay);
|
||||||
inThrottle = true;
|
|
||||||
setTimeout(() => (inThrottle = false), limit);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1327,6 +1324,7 @@ function initScrollPositionSaver() {
|
|||||||
function savePosition(event) {
|
function savePosition(event) {
|
||||||
// #959 if we fiddle around with the history during print preview
|
// #959 if we fiddle around with the history during print preview
|
||||||
// GC will close the preview immediatley
|
// GC will close the preview immediatley
|
||||||
|
console.log('savePosition', event);
|
||||||
if (isPrintPreview) {
|
if (isPrintPreview) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1341,7 +1339,7 @@ function initScrollPositionSaver() {
|
|||||||
if (!ticking) {
|
if (!ticking) {
|
||||||
window.requestAnimationFrame(function () {
|
window.requestAnimationFrame(function () {
|
||||||
// #996 GC is so damn slow that we need further throttling
|
// #996 GC is so damn slow that we need further throttling
|
||||||
throttle(savePosition, 250);
|
debounce(savePosition, 200)();
|
||||||
ticking = false;
|
ticking = false;
|
||||||
});
|
});
|
||||||
ticking = true;
|
ticking = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user