Skip to content

Commit 42e26ef

Browse files
stevennovaryoservo-wpt-sync
authored andcommitted
Add IntersectionObserver WPT
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
1 parent bed65a4 commit 42e26ef

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<title>IntersectionObserver observing table with border and overflow scroll</title>
3+
<link rel="author" href="mailto:steven.novaryo@gmail.com" title="Steven Novaryo">
4+
<link rel="help" href="https://w3c.github.io/IntersectionObserver/#intersectionobserver-root-intersection-rectangle">
5+
<link rel="help" href="https://drafts.csswg.org/css-tables/#global-style-overrides">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="./resources/intersection-observer-test-utils.js"></script>
9+
10+
<style>
11+
#root {
12+
box-sizing: border-box;
13+
overflow: scroll;
14+
border: 50px solid black;
15+
will-change: transform;
16+
}
17+
#target {
18+
display: inline-block;
19+
width: 50px;
20+
height: 50px;
21+
position: absolute;
22+
top: 300px;
23+
left: 300px;
24+
background-color: green;
25+
}
26+
</style>
27+
<table id="root">
28+
<tr>
29+
<td>
30+
<span id="target"></span>
31+
</td>
32+
</tr>
33+
</table>
34+
<script>
35+
var entries = [];
36+
var rootRect = root.getBoundingClientRect();
37+
38+
runTestCycle(function() {
39+
assert_true(!!target, "target exists");
40+
var observer = new IntersectionObserver(function(changes) {
41+
entries = entries.concat(changes)
42+
}, { root: root });
43+
observer.observe(target);
44+
entries = entries.concat(observer.takeRecords());
45+
assert_equals(entries.length, 0, "No initial notifications.");
46+
runTestCycle(step0, "First rAF.");
47+
}, "IntersectionObserver observing an element inside a root table.");
48+
49+
function step0() {
50+
// To reduce the inconsistencies of the layout within different UAs we are calculating the offset dynamically.
51+
var targetRect = target.getBoundingClientRect();
52+
target.style.top = `${300 - (targetRect.top - rootRect.bottom + 50)}px`;
53+
target.style.left = `${300 - (targetRect.left - rootRect.right + 50)}px`;
54+
runTestCycle(step1, "Moving the target to the right bottom corner of the table.");
55+
checkLastEntry(entries, 0, [
56+
targetRect.left, targetRect.right, targetRect.top, targetRect.bottom,
57+
0, 0, 0, 0,
58+
rootRect.left, rootRect.right, rootRect.top, rootRect.bottom,
59+
false
60+
]);
61+
}
62+
63+
function step1() {
64+
var targetRect = target.getBoundingClientRect();
65+
checkLastEntry(entries, 1, [
66+
targetRect.left, targetRect.right, targetRect.top, targetRect.bottom,
67+
targetRect.left, targetRect.right, targetRect.top, targetRect.bottom,
68+
rootRect.left, rootRect.right, rootRect.top, rootRect.bottom,
69+
true
70+
]);
71+
}
72+
73+
</script>

0 commit comments

Comments
 (0)