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

adapt_framework: inview does not measure out-of-bounds correctly #3098

Closed
oliverfoster opened this issue Mar 23, 2021 · 0 comments · Fixed by #3099
Closed

adapt_framework: inview does not measure out-of-bounds correctly #3098

oliverfoster opened this issue Mar 23, 2021 · 0 comments · Fixed by #3099
Assignees
Labels

Comments

@oliverfoster
Copy link
Member

oliverfoster commented Mar 23, 2021

The isOutOfBounds function in inview.js assumes that a child will be out-of-bounds in a scrolled container. It is possible to position an element outside of the visible bounds of a parent using many other methods. Checking for container scrolling before checking child offsets is poor logic.

isOutOfBounds: function(element, parent) {
var isScrollWidthOverflowing = (parent.clientWidth < parent.scrollWidth);
var isScrollHeightOverflowing = (parent.clientHeight < parent.scrollHeight);
var isOverflowing = (isScrollWidthOverflowing || isScrollHeightOverflowing);
var $parent = $(parent);
if (!isOverflowing || ($parent.css("overflow") === "visible")) {
return false;
}
var $element = $(element);
var childPos = $element.offset();
var parentPos = $parent.offset();
var childOffsetTop = (childPos.top - parentPos.top);
var childOffsetLeft = (childPos.left - parentPos.left);
var childOffsetBottom = (childOffsetTop + element.clientHeight);
var childOffsetRight = (childOffsetLeft + element.clientWidth);
// check inclusive of bounding rectangle edges
var isOutOfBounds = (childOffsetTop >= parent.clientHeight
|| childOffsetLeft >= parent.clientWidth
|| childOffsetBottom <= 0
|| childOffsetRight <= 0);
return isOutOfBounds;
}

Example:
When a 3 item narrative is moved to the last item, the middle item is currently considered onscreen. $('.narrative__slider-image-container[data-index=1]').onscreen().onscreen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant