49 lines
1.8 KiB
HTML
49 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<title>IntersectionObserver observing an SVG <rect> element with changing 'transform'</title>
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="resources/intersection-observer-test-utils.js"></script>
|
|
<svg id="container" width="10" height="10" viewBox="0 0 128 128" style="background: lightblue; position: absolute; top: 0; left: 0;">
|
|
<rect id="target" x="0" y="0" width="128" height="128" fill="green"></rect>
|
|
</svg>
|
|
<script>
|
|
const viewportWidth = document.documentElement.clientWidth;
|
|
const viewportHeight = document.documentElement.clientHeight;
|
|
setup(() => {
|
|
window.entries = [];
|
|
window.target = document.getElementById("target");
|
|
window.targetRect = target.getBoundingClientRect();
|
|
});
|
|
runTestCycle(function() {
|
|
assert_true(!!target, "target exists");
|
|
const observer = new IntersectionObserver(function(changes) {
|
|
entries = entries.concat(changes);
|
|
}, {root: container, threshold: [0, 0.5, 1]});
|
|
observer.observe(target);
|
|
entries = entries.concat(observer.takeRecords());
|
|
assert_equals(entries.length, 0, "No initial notifications");
|
|
runTestCycle(step0, "First rAF.");
|
|
});
|
|
function step0() {
|
|
target.setAttribute('y', '-64');
|
|
runTestCycle(step1, "change target's y property to -64)");
|
|
// The numbers in brackets are target client rect; intersection rect;
|
|
// and root bounds.
|
|
checkLastEntry(entries, 0, [
|
|
0, targetRect.width, 0, targetRect.height,
|
|
0, targetRect.width, 0, targetRect.height,
|
|
0, 10, 0, 10,
|
|
true,
|
|
]);
|
|
}
|
|
function step1() {
|
|
target.style.transform = "translate(0, 50px)";
|
|
checkLastEntry(entries, 1, [
|
|
0, targetRect.width, -5, -5 + targetRect.height,
|
|
0, targetRect.width, 0, -5 + targetRect.height,
|
|
0, 10, 0, 10,
|
|
true,
|
|
]);
|
|
}
|
|
</script>
|