Skip to content

Commit 8b34db8

Browse files
committed
add intersection observer to improve performance
1 parent c159d93 commit 8b34db8

File tree

1 file changed

+10
-1
lines changed
  • packages/frontendmu-nuxt/components/site

1 file changed

+10
-1
lines changed

packages/frontendmu-nuxt/components/site/Menu.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,16 @@ function toggleHeader() {
140140
lastScrollPosition = currentScrollPosition;
141141
};
142142
143-
window.addEventListener("scroll", handleScroll);
143+
const observer = new IntersectionObserver(
144+
([entry]) => {
145+
if (entry.isIntersecting) {
146+
window.addEventListener("scroll", handleScroll, { passive: true });
147+
}
148+
},
149+
{ threshold: 0 }
150+
);
151+
152+
observer.observe($header);
144153
}
145154
}
146155

0 commit comments

Comments
 (0)