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 bug if the immediate offset parent is not also the immediate scrollable parent #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

theKidOfArcrania
Copy link

@theKidOfArcrania theKidOfArcrania commented Nov 25, 2016

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.
@theKidOfArcrania theKidOfArcrania changed the title Fix bug if the immediate offset-parent is not scrollable Fix bug if the immediate offset-parent is not scrollable, and vice versa Nov 25, 2016
@theKidOfArcrania theKidOfArcrania changed the title Fix bug if the immediate offset-parent is not scrollable, and vice versa Fix bug if the immediate offset parent is not also the immediate scrollable parent Nov 25, 2016
This accounts for when the immediate scrollable parent isn't also positioned.
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.

1 participant