summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/intersection-observer/resources/scaled-target-subframe.html
blob: 8f6f930e00915417fcba592df5520999c427ed91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<style>
html, body {
  margin: 0;
}
#target {
  width: 100px;
  height: 100px;
}
</style>

<div id="target">target</div>

<script>
var delay = 100;
var results = [];

function waitForNotification(f) {
  setTimeout(() => {
    requestAnimationFrame(function () {
      requestAnimationFrame(function () {
        setTimeout(f)
      })
    })
  }, delay)
}

window.addEventListener("message", event => {
  waitForNotification(() => {
    window.parent.postMessage(results.map(e => e.isVisible), "*");
    results = [];
  });
});

onload = () => {
  var target = document.getElementById("target");
  var observer = new IntersectionObserver(entries => {
    results = entries;
  }, {trackVisibility: true, delay: delay});
  observer.observe(document.getElementById("target"));
  window.parent.postMessage("", "*");
};
</script>