Skip to content

Commit 66c5787

Browse files
committed
ENH: Use InteractionObserver API to load iframe
1 parent 490b639 commit 66c5787

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

β€Žindex.htmlβ€Ž

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,23 @@ <h3 id="example" class="title has-text-centered">
358358
</div>
359359
</div>
360360
<div class="snippet snippet-plot has-text-centered" style="background: white">
361-
<iframe src="example.html" id="iframe" loading="lazy"
361+
<iframe data-src="example.html" id="iframe" loading="lazy"
362362
style="width:100%; margin-top:1em; height:566px; overflow:hidden;"
363363
data-ga-on="wheel" data-ga-event-category="iframe" data-ga-event-action="wheel"></iframe>
364+
<noscript>JavaScript is required.</noscript>
365+
<script>
366+
var iframe = document.getElementById('iframe');
367+
if (! window.IntersectionObserver) {
368+
window.addEventListener('load', () => { iframe.src = iframe.dataset.src; });
369+
} else {
370+
(new IntersectionObserver((entries, observer) => {
371+
if (entries[0].intersectionRatio === 0)
372+
return;
373+
iframe.src = iframe.dataset.src;
374+
observer.disconnect();
375+
}, {threshold: .01})).observe(iframe);
376+
}
377+
</script>
364378
</div>
365379

366380
<div class="columns content is-centered is-vcentered has-text-centered" style="margin-top:2em;">

0 commit comments

Comments
Β (0)