Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: container will be null when at a shadowRoot #27

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading