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: positioned element offset when containing block has transform #1368

Merged
merged 7 commits into from
Apr 29, 2022

Conversation

temper357
Copy link
Contributor

@temper357 temper357 commented Apr 28, 2022

Closes #1364

修复当 positioned element 的 containing block 有 transform 时,positioned element 的定位错误加上了 transform 的值。

  • 原因:当 positioned element 无 top/bottom 或者 left/right 时,其定位应使用 renderPositionPlaceholder 的 offset,renderPositionPlaceholder 相对于 parent 的定位使用的是 localToGlobal 来计算,而 localToGlobal 使用的是 applyPaintTransform,paint transform 中又包含了 transform offset,导致 issue 中的例子错误了加上 parent 的 transform offset。同理 element 上的 offsetTop 与 offsetLeft API 的实现由于也使用 localToGlobal 也会有相同问题。

  • fix: 针对上面两种 case 定义一个新的方法 getOffsetToAncestor,positioned element 的定位需要考虑 layout offset 与 scroll offset,而 offsetTop 与 offsetLeft API 只需要考虑 layout offset,与 scroll offset 无关。

@temper357 temper357 changed the title [WIP] fix: positioned element offset when containing block has transform fix: positioned element offset when containing block has transform Apr 29, 2022
@yuanyan yuanyan merged commit 6995a56 into main Apr 29, 2022
@yuanyan yuanyan deleted the fix/positioned-element-offset branch April 29, 2022 09:54
wssgcg1213 added a commit that referenced this pull request May 7, 2022
yuanyan pushed a commit that referenced this pull request May 7, 2022
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.

positioned element 相对的 containing block 的 element 有 transform 时出现定位错误
4 participants