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: offsetTop and offsetLeft should relative to body element if no positioned parent found #1041

Merged
merged 5 commits into from Jan 6, 2022

Conversation

temper357
Copy link
Contributor

@temper357 temper357 commented Dec 30, 2021

Closes #1000

  • offsetTop/offsetLeft 是相对于 offsetParent 定位,offsetParent 指的是最近的 position 为非 static 的 parent,当 offsetParent 找不到时默认应使用 body element,而不是 html element。

wssgcg1213
wssgcg1213 previously approved these changes Jan 4, 2022
|| renderStyle.position == CSSPositionType.fixed
|| this is BodyElement
|| this == ownerDocument.documentElement) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里文档里说的 terminate 我感觉是直接返回当前对象, 不过效率上这样更好一点, 所以我 accept 了

@answershuto answershuto merged commit 9f07b7e into main Jan 6, 2022
@answershuto answershuto deleted the fix/offset-top-left branch January 6, 2022 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

滚动是文档中的元素的offsetTop应该不变
5 participants