fix: calc scrollheight dynamically for tabs change

This commit is contained in:
jialin
2025-11-10 20:40:15 +08:00
parent 285e274818
commit 9eb1dba4a1
14 changed files with 283 additions and 77 deletions
+32 -8
View File
@@ -217,12 +217,6 @@ export default function useOverlayScroller(data?: {
// const currentScroll = instanceRef.current?.scroll().position.y;
const targetPos = targetRect.top - containerRect.top + currentScroll;
console.log(
'target=======',
currentScroll,
targetPos,
instanceRef.current?.options()
);
scrollEventElement.current.scroll({
y: targetPos - offset,
@@ -231,6 +225,35 @@ export default function useOverlayScroller(data?: {
instanceRef.current?.update?.();
};
const getScrollElementScrollableHeight = () => {
if (!instanceRef.current || !scrollEventElement.current) {
instanceRef.current = instance?.();
scrollEventElement.current =
instanceRef.current?.elements()?.scrollEventElement;
}
const scrollerState = instanceRef.current?.state();
const overflowAmount = scrollerState?.overflowAmount;
const scrollOffsetElement = instanceRef.current?.elements().viewport;
console.log('osInstance==========', overflowAmount, scrollOffsetElement, {
top:
Math.round(
(overflowAmount?.y - scrollOffsetElement?.scrollTop || 0) /
overflowAmount?.y
) * overflowAmount?.y,
scrollTop: scrollOffsetElement?.scrollTop,
scrollLeft: scrollOffsetElement?.scrollLeft,
scrollHeight:
scrollOffsetElement?.scrollHeight - scrollOffsetElement?.clientHeight
});
return {
scrollTop: scrollOffsetElement?.scrollTop,
scrollHeight:
scrollOffsetElement?.scrollHeight - scrollOffsetElement?.clientHeight
};
};
useEffect(() => {
return () => {
instanceRef.current?.destroy?.();
@@ -240,9 +263,10 @@ export default function useOverlayScroller(data?: {
return {
initialize: createInstance,
instance: instanceRef.current,
scrollEventElement: scrollEventElement.current,
instance: instanceRef,
scrollEventElement: scrollEventElement,
initialized: initialized.current,
getScrollElementScrollableHeight,
generateInstance,
destroyInstance: destroyInstance,
updateScrollerPosition: throttledUpdateScrollerPosition,