Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<title>scrollIntoView on an SVG container element</title>
<link rel="help" href="https://bugzil.la/2091995">
<meta name="viewport" content="user-scalable=no">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<svg width="8000" height="8000">
<defs>
<rect id="def" width="100" height="100" fill="blue"/>
</defs>
<g id="group"><rect width="100" height="100" fill="blue" x="1950" y="1950"/></g>
<g id="translated" transform="translate(2950, 2950)">
<rect width="100" height="100" fill="blue"/>
</g>
<g id="nested"><g><rect width="100" height="100" fill="blue" x="3950" y="3950"/></g></g>
<use id="use" href="#def" x="4950" y="4950"/>
</svg>
<script>
add_completion_callback(() => {
document.querySelector("svg").remove();
window.scrollTo(0, 0);
});
for (let id of [ "group", "translated", "nested", "use" ]) {
test(t => {
let target = document.getElementById(id);
window.scrollTo(0, 0);
let bounds = target.getBoundingClientRect();
let expected = { x: bounds.left, y: bounds.top };
assert_not_equals(window.scrollX, expected.x, "x before scroll");
assert_not_equals(window.scrollY, expected.y, "y before scroll");
target.scrollIntoView({ block: "start", inline: "start" });
assert_approx_equals(window.scrollX, expected.x, 1, "x after scroll");
assert_approx_equals(window.scrollY, expected.y, 1, "y after scroll");
}, document.title + ", " + id);
test(t => {
let target = document.getElementById(id);
let bounds = target.getBoundingClientRect();
window.scrollTo(window.scrollX + bounds.left - 10,
window.scrollY + bounds.top - 10);
let before = { x: window.scrollX, y: window.scrollY };
target.scrollIntoView({ block: "nearest", inline: "nearest" });
assert_equals(window.scrollX, before.x, "x after scroll");
assert_equals(window.scrollY, before.y, "y after scroll");
}, document.title + ", " + id + ", nearest on a fully visible element");
}
</script>