mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
committed by
Andrey Lushnikov
parent
4f8d00e64e
commit
96c558d544
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user