summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/intersection-observer/resources/intersection-ratio-with-fractional-bounds-in-iframe-content.html
blob: 696ebf6ebe5cf2dc27c7b028744de7a5584090b9 (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
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            margin: 0;
            height: 100%;
        }
        .app {
            display: flex;
            width: 100%;
        }
        .sidebar {
            width: 31.1%;
            margin: 0;
            background: rgb(231, 249, 139);
        }
        section {
            width: 68.9%;
            background-color: rgb(119, 219, 172);
            border: dashed red 3px;
        }
        p {
            margin-top: 0;
        }
    </style>
</head>
<body>
    <div class=app>
        <div class="sidebar"></div>
        <section id=target>
            <h2>Observer target</h2>
            <p><strong>Intersection ratio:</strong> <span id=ratio></span></p>
        </section>
    </div>

    <script>
        const onIntersection = entries => {
            const ratio = entries[0].intersectionRatio;
            const eventData = { intersectionRatio: ratio };
            document.getElementById("ratio").innerText = ratio.toFixed(5);
            const event = new CustomEvent("iframeObserved", {detail: eventData});
            parent.document.dispatchEvent(event);
        };
        const observer = new IntersectionObserver(onIntersection, {threshold: 1});
        setTimeout(() => {observer.observe(document.getElementById("target"))}, 0);
    </script>
</body>
</html>