Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-scroll-snap/scroll-margin-visibility-check.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body { margin: 0 }
#scroller {
height: 500px;
width: 500px;
scrollbar-width: none;
overflow: scroll;
}
#target {
width: 100px;
height: 100px;
background-color: blue;
scroll-margin: 100px;
margin-left: 510px;
}
</style>
<div id="scroller">
<div style="width: 450px; height: 450px;"></div>
<div tabindex="0" id="target"></div>
<div style="width: 2000px; height: 2000px;"></div>
</div>
<script>
let scroller = document.getElementById("scroller");
let target = document.getElementById("target");
promise_test(async function() {
scroller.scrollTo(0, 0);
await new Promise(resolve => {
scroller.addEventListener("scroll", resolve, { once: true });
document.getElementById("target").focus();
});
assert_true(scroller.scrollTop > 0, "Visibility check should not account for margin");
assert_true(scroller.scrollLeft > 0, "Visibility check should not account for margin");
});
</script>