feat(elementhandle): introduce elementHandle.isIntersectingViewport() method. (#2673)

This patch introduces  `elementHandle.isIntersectingViewport()` method returns
true if element is visible in the viewport.

Fixes #2629.
This commit is contained in:
Bogdan Ponomarenko
2018-07-12 03:51:04 +03:00
committed by Andrey Lushnikov
parent 4f8d00e64e
commit 96c558d544
3 changed files with 71 additions and 0 deletions

View File

@@ -354,6 +354,24 @@ class ElementHandle extends JSHandle {
}
return result;
}
/**
* @returns {!Promise<boolean>}
*/
isIntersectingViewport() {
return this.executionContext().evaluate(
node => new Promise(resolve => {
const callback = entries => {
resolve(entries[0].isIntersecting);
observer.disconnect();
};
const observer = new IntersectionObserver(callback);
observer.observe(node);
}),
this
);
}
}
function computeQuadArea(quad) {