refactor(affix): throttle scroll

This commit is contained in:
07akioni 2021-04-21 12:15:24 +08:00
parent eeb48edca4
commit 1fb128b821

View File

@ -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