Fix bug if the immediate offset parent is not also the immediate scrollable parent #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The original code uses
Element.offsetTop
andElement.offsetLeft
to determine the offsets for the element within theElement.offsetParent
. The code assumes that theoffsetParent
is the parent closest to the node that is scrollable. However, this is not always the case. The API says that the offsetParent is the parent closes the node that is positioned (i.e. hasposition: relative
orposition: absolute
in the css), or it returnsbody
if none of the parents are positioned. The code would run into a problem if one of the node's parents are positioned, but none of them are scrollable (it would use the offsets of the positioned parent and use those numbers to scroll the body). It would also run into a problem if one of the node's parents are scrollable, but aren't positioned (i.e. if you set amax-height
in the css and also setoverflow-y: scroll
).