Skip to content

Commit

Permalink
Adds x and y to IntersectionObserverEntry (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhassan1 committed Aug 10, 2022
1 parent ac89bee commit 0a37f6e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion polyfills/IntersectionObserver/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ IntersectionObserver.prototype._getRootRect = function() {
var html = document.documentElement;
var body = document.body;
rootRect = {
x: 0,
y: 0,
top: 0,
left: 0,
right: html.clientWidth || body.clientWidth,
Expand Down Expand Up @@ -449,6 +451,8 @@ IntersectionObserver.prototype._expandRectByRootMargin = function(rect) {
};
newRect.width = newRect.right - newRect.left;
newRect.height = newRect.bottom - newRect.top;
newRect.x = newRect.left;
newRect.y = newRect.top;

return newRect;
};
Expand Down Expand Up @@ -616,6 +620,8 @@ function computeRectIntersection(rect1, rect2) {
var height = bottom - top;

return (width >= 0 && height >= 0) && {
x: left,
y: top,
top: top,
bottom: bottom,
left: left,
Expand Down Expand Up @@ -644,8 +650,10 @@ function getBoundingClientRect(el) {
if (!rect) return getEmptyRect();

// Older IE
if (!(rect.width && rect.height)) {
if (!(rect.width && rect.height && rect.x && rect.y)) {
rect = {
x: rect.left,
y: rect.top,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
Expand All @@ -665,6 +673,8 @@ function getBoundingClientRect(el) {
*/
function getEmptyRect() {
return {
x: 0,
y: 0,
top: 0,
bottom: 0,
left: 0,
Expand Down

0 comments on commit 0a37f6e

Please sign in to comment.