.position() returns an offset from the static element on IE and Edge
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 59.8k
- Forks
- 20.4k
- Avg merge
- 17h 32m
- Merged PRs (30d)
- 4
Description
The following code is an implementation of .position() from jquery-3.4.1.js.
// Account for the *real* offset parent, which can be the document or its root element
// when a statically positioned element is identified
doc = elem.ownerDocument;
offsetParent = elem.offsetParent || doc.documentElement;
while ( offsetParent &&
( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
jQuery.css( offsetParent, "position" ) === "static" ) {
offsetParent = offsetParent.parentNode;
}
Does the .position() need the parent of root only ?
I do not think so.
If so, the code should be "if" and not "while".
( offsetParent === doc.body || offsetParent === doc.documentElement )
is not repeat condition, it is break condition I think.
In IE and Edge, if the target element in the table, the .position() returns offset from the table-cell (it's IE and Edge's offsetParent).
I guess the code is intended to be:
!( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
Note by @mgol: I edited the post to add code formatting. (2019-07-01)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the .position() implementation shown from jquery-3.4.1.js and reproduce the behavior in IE or Edge using a target inside a table. Trace how offsetParent is handled for table elements, then verify the intended offset behavior with a focused regression test covering that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100