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-padding-and-margin.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<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;
scroll-padding: 10px;
scrollbar-width: none;
overflow: hidden;
}
#target {
width: 100px;
height: 100px;
background-color: blue;
scroll-margin: 10px;
margin-left: 1000px;
}
</style>
<div id="scroller">
<div style="width: 2000px; height: 2000px;"></div>
<div id="target"></div>
<div style="width: 2000px; height: 2000px;"></div>
</div>
<script>
let scroller = document.getElementById("scroller");
let target = document.getElementById("target");
test(() => {
scroller.scrollTo(0, 0);
target.scrollIntoView({ block: "start", inline: "start" });
assert_equals(scroller.scrollTop, 2000 - 20, "Top should account for margin + padding");
assert_equals(scroller.scrollLeft, 1000 - 20, "Left should account for margin + padding");
});
test(() => {
scroller.scrollTo(0, 0);
target.scrollIntoView({ block: "end", inline: "end" });
assert_equals(scroller.scrollTop, 2000 - 500 + 100 + 20, "Top should account for margin + padding");
assert_equals(scroller.scrollLeft, 1000 - 500 + 100 + 20, "Left should account for margin + padding");
});
</script>