Skip to content

Commit

Permalink
fix: container will be null when at shadowRoot (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 authored Nov 30, 2023
1 parent f05f2a9 commit 8d9cdc3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,17 @@ function getOffsetParent(element: HTMLElement): HTMLElement | null {
* @returns
*/
export function getViewPort(container: HTMLElement): HTMLElement {
const fallbackViewportElement = document.documentElement;

if (!container) {
return fallbackViewportElement;
}

// 若 container 本身就是滚动容器,则直接返回
if (isContentClippedElement(container)) {
return container;
}

const fallbackViewportElement = document.documentElement;

// 若 container 的 position 是 absolute 或 fixed,则有可能会脱离其最近的滚动容器,需要根据 offsetParent 和 containing block来综合判断
if (['fixed', 'absolute'].includes(getStyle(container, 'position'))) {
// 先获取定位节点(若无则使用 containerBlock)
Expand Down

0 comments on commit 8d9cdc3

Please sign in to comment.