admin管理员组文章数量:1426797
I need to detect if my iframe which is loaded from another domain is in viewport.
This works fine native in Chromem,Firefox and IE called Intersection Observer. However this is not working in Safari.
There has been created a polyfill for this: Github link and should be working on Safari as well.
I tested it using this code:
Site A:
<html>
<head>
</head>
<body>
A lot of text here so the iframe is not inview.
A lot of text here so the iframe is not inview.
<br>
<br>
.
.
.
.
.
.
.
<br>
A lot of text here so the iframe is not inview.
<iframe src="//siteB/test.html" frameborder="0" border="0" scroll="no" scrolling="no" width="300" height="250" style="border: 0px; overflow: hidden !important;"></iframe>
</body>
</html>
Site B:
<html>
<head>
<script src="intersection-observer.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
//do work
var io = new IntersectionObserver(
entries => {
console.log(entries);
if (entries["0"].isIntersecting) {
alert("inview");
}
},
{
/* Using default options. Details below */
}
);
// Start observing an element
var img1 = document.getElementById("img1");
console.log(img1);
io.observe(img1);
});
</script>
</head>
<body>
<img id="img1" src="motor.gif" style="position:absolute; top:0px; left:0px"/>
</body>
</html>
However I've tested this on an Iphone 6 however it immediatly does the alert and after clicking the alert away it doesn't show up anymore when scrolling up and down.
The intersection-observer-test.html page they included return passes for all 25 tests.
Anyone have a solution to this?
I need to detect if my iframe which is loaded from another domain is in viewport.
This works fine native in Chromem,Firefox and IE called Intersection Observer. However this is not working in Safari.
There has been created a polyfill for this: Github link and should be working on Safari as well.
I tested it using this code:
Site A:
<html>
<head>
</head>
<body>
A lot of text here so the iframe is not inview.
A lot of text here so the iframe is not inview.
<br>
<br>
.
.
.
.
.
.
.
<br>
A lot of text here so the iframe is not inview.
<iframe src="//siteB./test.html" frameborder="0" border="0" scroll="no" scrolling="no" width="300" height="250" style="border: 0px; overflow: hidden !important;"></iframe>
</body>
</html>
Site B:
<html>
<head>
<script src="intersection-observer.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
//do work
var io = new IntersectionObserver(
entries => {
console.log(entries);
if (entries["0"].isIntersecting) {
alert("inview");
}
},
{
/* Using default options. Details below */
}
);
// Start observing an element
var img1 = document.getElementById("img1");
console.log(img1);
io.observe(img1);
});
</script>
</head>
<body>
<img id="img1" src="motor.gif" style="position:absolute; top:0px; left:0px"/>
</body>
</html>
However I've tested this on an Iphone 6 however it immediatly does the alert and after clicking the alert away it doesn't show up anymore when scrolling up and down.
The intersection-observer-test.html page they included return passes for all 25 tests.
Anyone have a solution to this?
Share Improve this question edited Jun 27, 2018 at 12:31 Nikola Lukic 4,2666 gold badges48 silver badges80 bronze badges asked Jun 27, 2018 at 11:51 user3605780user3605780 7,09213 gold badges46 silver badges71 bronze badges 1- 1 Try to implement code snippet if is possible. – Nikola Lukic Commented Jun 27, 2018 at 12:06
1 Answer
Reset to default 4I saw a issue on github where it outlined safari getting the incorrect height because of quirks mode : https://github./w3c/IntersectionObserver/issues/282 . Maybe add
<!DOCTYPE html>
<html>
can fix it.
本文标签: javascriptintersection observer polyfill not working SafariStack Overflow
版权声明:本文标题:javascript - intersection observer polyfill not working Safari - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745396136a2656821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论