[skip ci] perf(web): improve little performance

This commit is contained in:
Xwite
2023-05-14 14:03:55 +08:00
parent 624f993d34
commit 152dc4e3b8
7 changed files with 39 additions and 38 deletions

View File

@@ -71,10 +71,10 @@ const scrollToReadedLength = (length) => {
defineExpose({
scrollToReadedLength,
});
const observer = ref(null);
let intersectionObserver = null;
const emit = defineEmits(["readedLengthChange"]);
onMounted(() => {
observer.value = new IntersectionObserver(
intersectionObserver = new IntersectionObserver(
(entries) => {
for (let { target, isIntersecting } of entries) {
if (isIntersecting) {
@@ -90,15 +90,15 @@ onMounted(() => {
rootMargin: `0px 0px -${window.innerHeight - 24}px 0px`,
}
);
observer.value.observe(titleRef.value);
intersectionObserver.observe(titleRef.value);
paragraphRef.value.forEach((element) => {
observer.value.observe(element);
intersectionObserver.observe(element);
});
});
onUnmounted(() => {
observer.value?.disconnect();
observer.value = null;
intersectionObserver?.disconnect();
intersectionObserver = null;
});
</script>