22 <view :style =" `${rootStyle};display: inline-block;`" >
33 <!-- 强制设置高宽,防止元素坍塌-->
44 <!-- 在使用 wd-sticky-box 时,某些情况下 wd-sticky__container 的 'position:absolute' 需要相对于 wd-sticky-box-->
5- <view :class =" `wd-sticky ${props. customClass}`" :style =" stickyStyle" :id =" styckyId" >
5+ <view :class =" `wd-sticky ${customClass}`" :style =" stickyStyle" :id =" styckyId" >
66 <!-- 吸顶容器-->
77 <view class =" wd-sticky__container" :style =" containerStyle" >
88 <!-- 监听元素尺寸变化-->
@@ -20,15 +20,15 @@ export default {
2020 name: ' wd-sticky' ,
2121 options: {
2222 addGlobalClass: true ,
23- // virtualHost: true,
23+ virtualHost: true ,
2424 styleIsolation: ' shared'
2525 }
2626}
2727 </script >
2828
2929<script lang="ts" setup>
3030import { type Ref , computed , getCurrentInstance , inject , ref } from ' vue'
31- import { addUnit , getRect , objToStyle , uuid } from ' ../common/util'
31+ import { addUnit , getRect , objToStyle , requestAnimationFrame , uuid } from ' ../common/util'
3232import { stickyProps } from ' ./types'
3333
3434const props = defineProps (stickyProps )
@@ -116,9 +116,11 @@ function resizeHandler(detail: any) {
116116 width .value = detail .width
117117 height .value = detail .height
118118 // // 如果和 wd-sticky-box 配套使用,吸顶逻辑交由 wd-sticky-box 进行处理
119- observerContentScroll ()
120- if (! observerForChild ) return
121- observerForChild (proxy )
119+ requestAnimationFrame (() => {
120+ observerContentScroll ()
121+ if (! observerForChild ) return
122+ observerForChild (proxy )
123+ })
122124}
123125/**
124126 * @description 模拟吸顶逻辑
@@ -132,7 +134,9 @@ function observerContentScroll() {
132134 .relativeToViewport ({
133135 top: - offset // viewport上边界往下拉
134136 })
135- .observe (` #${styckyId .value } ` , scrollHandler )
137+ .observe (` #${styckyId .value } ` , (result ) => {
138+ scrollHandler (result )
139+ })
136140 getRect (` #${styckyId .value } ` , false , proxy ).then ((res ) => {
137141 // 当 wd-sticky 位于 viewport 外部时不会触发 observe,此时根据位置手动修复位置。
138142 if (Number (res .bottom ) <= offset ) scrollHandler ({ boundingClientRect: res })
0 commit comments