mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-31 00:47:13 +00:00
scroll: fix high cpu usage #996
This commit is contained in:
parent
c4a8c278be
commit
7d78c9a6a4
2 changed files with 14 additions and 2 deletions
|
@ -1 +1 @@
|
||||||
7.3.1+4f182a115b0a3a6d4b6b2ba46abe3c4e71cfda5c
|
7.3.1+c4a8c278be4013f283872b4cbb88e4baa19b2988
|
|
@ -62,6 +62,17 @@ function adjustContentWidth() {
|
||||||
elc.style[dir_padding_end] = '' + end + 'px';
|
elc.style[dir_padding_end] = '' + end + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function throttle(func, limit) {
|
||||||
|
let inThrottle;
|
||||||
|
return function (...args) {
|
||||||
|
if (!inThrottle) {
|
||||||
|
func.apply(this, args);
|
||||||
|
inThrottle = true;
|
||||||
|
setTimeout(() => (inThrottle = false), limit);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function fixCodeTabs() {
|
function fixCodeTabs() {
|
||||||
/* if only a single code block is contained in the tab and no style was selected, treat it like style=code */
|
/* if only a single code block is contained in the tab and no style was selected, treat it like style=code */
|
||||||
var codeTabContents = Array.from(document.querySelectorAll('.tab-content.tab-panel-style')).filter(function (tabContent) {
|
var codeTabContents = Array.from(document.querySelectorAll('.tab-content.tab-panel-style')).filter(function (tabContent) {
|
||||||
|
@ -1311,7 +1322,8 @@ function initScrollPositionSaver() {
|
||||||
elc.addEventListener('scroll', function (event) {
|
elc.addEventListener('scroll', function (event) {
|
||||||
if (!ticking) {
|
if (!ticking) {
|
||||||
window.requestAnimationFrame(function () {
|
window.requestAnimationFrame(function () {
|
||||||
savePosition();
|
// #996 GC is so damn slow that we need further throttling
|
||||||
|
throttle(savePosition, 250);
|
||||||
ticking = false;
|
ticking = false;
|
||||||
});
|
});
|
||||||
ticking = true;
|
ticking = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue