mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2025-10-27 14:42:30 +01:00
Fix Forced reflow in menu scroll handler
A forced reflow occurs when JavaScript queries geometric properties (such as offsetWidth) after styles have been invalidated by a change to the DOM state. This can result in poor performance. https://pagespeed.web.dev/analysis/https-adityatelange-github-io-hugo-PaperMod/n5w29pnr5o?form_factor=mobile
This commit is contained in:
@@ -33,9 +33,14 @@
|
||||
{{- partial "extend_footer.html" . }}
|
||||
|
||||
<script>
|
||||
let menu = document.getElementById('menu')
|
||||
let menu = document.getElementById('menu');
|
||||
if (menu) {
|
||||
menu.scrollLeft = localStorage.getItem("menu-scroll-position");
|
||||
// Set the scroll position
|
||||
const scrollPosition = localStorage.getItem("menu-scroll-position");
|
||||
if (scrollPosition) {
|
||||
menu.scrollLeft = parseInt(scrollPosition, 10);
|
||||
}
|
||||
|
||||
menu.onscroll = function () {
|
||||
localStorage.setItem("menu-scroll-position", menu.scrollLeft);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user