检测 iFrame 中的元素是否在 Client-View 中

时间:2021-02-22 07:19:50

标签: javascript html jquery internet-explorer iframe

我想检测 <iframe> 中的元素是否在主框架的客户端视图中。

Example

我面临的问题是,对于 <iFrame>,该元素始终在 View 中。但我无法检测 Element 是否在主框架的视图中。

在此示例中,请认为元素 (Div) 位于 Pixel 2500。如果元素在视图中,我想从 <iframe> 外部进行检测

<html>
<body>
<div style="background-color: red;" width="100%">
Menu
</div>
<iframe src="https://stackoverflow.com/" width="100%" height="3000px">
</body>
</html>

需要在 IE 中工作

1 个答案:

答案 0 :(得分:0)

如果 IntersectionObserver 有效并且您希望在 IE 中支持它,则可以使用 this polyfill。该库在不支持的浏览器中填充了原生 IntersectionObserver API,并支持 IE 7+。