mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-03-20 16:15:09 +00: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
2 changed files with 7 additions and 9 deletions
|
@ -1 +1 @@
|
|||
7.3.2+de59e6700a230cecc75cebb1b225fe189f0189e7
|
||||
7.3.2+0dd98363fbc04746c77cd13539a0d1b3f1a9de8e
|
|
@ -62,14 +62,11 @@ function adjustContentWidth() {
|
|||
elc.style[dir_padding_end] = '' + end + 'px';
|
||||
}
|
||||
|
||||
function throttle(func, limit) {
|
||||
let inThrottle;
|
||||
let debounceTimeout;
|
||||
function debounce(func, delay) {
|
||||
return function (...args) {
|
||||
if (!inThrottle) {
|
||||
func.apply(this, args);
|
||||
inThrottle = true;
|
||||
setTimeout(() => (inThrottle = false), limit);
|
||||
}
|
||||
clearTimeout(debounceTimeout);
|
||||
debounceTimeout = setTimeout(() => func.apply(this, args), delay);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1327,6 +1324,7 @@ function initScrollPositionSaver() {
|
|||
function savePosition(event) {
|
||||
// #959 if we fiddle around with the history during print preview
|
||||
// GC will close the preview immediatley
|
||||
console.log('savePosition', event);
|
||||
if (isPrintPreview) {
|
||||
return;
|
||||
}
|
||||
|
@ -1341,7 +1339,7 @@ function initScrollPositionSaver() {
|
|||
if (!ticking) {
|
||||
window.requestAnimationFrame(function () {
|
||||
// #996 GC is so damn slow that we need further throttling
|
||||
throttle(savePosition, 250);
|
||||
debounce(savePosition, 200)();
|
||||
ticking = false;
|
||||
});
|
||||
ticking = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue