Skip to content

offsetTop/Left is sometimes wrong for getting the offset between container and body #12

Description

@meowtec

MDN:

The HTMLElement.offsetTop read-only property returns the distance of the outer border of the current element relative to the inner border of the top of the offsetParent node.

For some reasons the offsetParent sometimes could be some other node, not the body (scroll container).

Example (modify from the example code):

 <>
  <nav
+  style={{
+    padding: '200px 0',
+  }}
  >
    {lists.map((list) => (
      <button key={list} onClick={() => setSelected(list)}>
        {list}
      </button>
    ))}
  </nav>

+ <div style={{ position: 'absolute', width: '100%' }}>
    {selected === 'Fixed List' && <FixedSizeList />}
    {selected === 'Variable List' && <VariableSizeList />}
    {selected === 'Fixed Grid' && <FixedSizeGrid />}
    {selected === 'Variable Grid' && <VariableSizeGrid />}
+ </div>
</>

Would see some blank at the top of list.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions