Skip to content

Fix bug if the immediate offset parent is not also the immediate scrollable parent - #16

Open
theKidOfArcrania wants to merge 5 commits into
Arwid:masterfrom
theKidOfArcrania:master
Open

Fix bug if the immediate offset parent is not also the immediate scrollable parent#16
theKidOfArcrania wants to merge 5 commits into
Arwid:masterfrom
theKidOfArcrania:master

Conversation

@theKidOfArcrania

@theKidOfArcraniatheKidOfArcrania commented Nov 25, 2016

Copy link
Copy Markdown

The original code uses Element.offsetTop and Element.offsetLeft to determine the offsets for the element within the Element.offsetParent. The code assumes that the offsetParent 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. has position: relative or position: absolute in the css), or it returns body 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 a max-height in the css and also set overflow-y: scroll).

If the immediate parent was not scrollable, the code would attempt to find the first parent that is scrollable. However, it did not account for any offsets in elY that occur as we find the parent that is scrollable. Hence, it would scroll a bit (a lot) higher than where the intended element actually is.
If the immediate parent was not scrollable, the code would attempt to find the first parent that is scrollable. However, it did not account for any offsets in `elY` that occur as we find the parent that is scrollable. Hence, it would scroll a bit (a lot) higher than where the intended element actually is.
@theKidOfArcraniatheKidOfArcrania changed the title Fix bug if the immediate offset-parent is not scrollableFix bug if the immediate offset-parent is not scrollable, and vice versaNov 25, 2016
@theKidOfArcraniatheKidOfArcrania changed the title Fix bug if the immediate offset-parent is not scrollable, and vice versaFix bug if the immediate offset parent is not also the immediate scrollable parentNov 25, 2016
This accounts for when the immediate scrollable parent isn't also positioned.
Sign up for freeto 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.

1 participant

@theKidOfArcrania