From 1fb128b8212d0e42eee95790a70619daaa57c212 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Wed, 21 Apr 2021 12:15:24 +0800 Subject: [PATCH] refactor(affix): throttle scroll --- src/affix/src/Affix.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/affix/src/Affix.tsx b/src/affix/src/Affix.tsx index ad3f13886..2b6393936 100644 --- a/src/affix/src/Affix.tsx +++ b/src/affix/src/Affix.tsx @@ -8,7 +8,7 @@ import { PropType, h } from 'vue' -import { getScrollParent, unwrapElement } from 'seemly' +import { getScrollParent, unwrapElement, beforeNextFrameOnce } from 'seemly' import { useConfig, useStyle } from '../../_mixins' import { warn, keysOf } from '../../_utils' import type { ExtractPublicPropTypes } from '../../_utils' @@ -108,7 +108,11 @@ export default defineComponent({ handleScroll() } } - const handleScroll = (): void => { + function handleScroll (): void { + beforeNextFrameOnce(_handleScroll) + } + + function _handleScroll (): void { const { value: containerEl } = scrollElementRef const { value: selfEl } = selfRef if (!containerEl || !selfEl) return