@@ -1309,6 +1309,42 @@ The <dfn method for=Element caniuse=scrollintoview>scrollIntoView(<var>arg</var>
13091309 with <var> behavior</var> , <var> block</var> , <var> inline</var> , and <var> container</var> .
131013101. Optionally perform some other action that brings the element to the user's attention.
13111311
1312+ <div class='example'>
1313+ A component can use scrollIntoView to scroll content of interest into the specified alignment:
1314+
1315+ <pre><code highlight="html">
1316+ <style>
1317+ .scroller { overflow: auto; scroll-padding: 8px; }
1318+ .slide { scroll-margin: 16px; scroll-snap-align: center; }
1319+ </style>
1320+ <div class="carousel">
1321+ <div class="slides scroller">
1322+ <div id="s1" class="slide">
1323+ <div id="s2" class="slide">
1324+ <div id="s3" class="slide">
1325+ </div>
1326+ <div class="markers">
1327+ <button data-target="s1">1</button>
1328+ <button data-target="s2">2</button>
1329+ <button data-target="s3">3</button>
1330+ </div>
1331+ </div>
1332+ <script>
1333+ document.querySelector('.markers' ).addEventListener('click' , (evt) => {
1334+ const target = document.getElementById(evt.target.dataset.target);
1335+ if (!target) return;
1336+ // scrollIntoView correctly aligns target item respecting scroll-snap-align,
1337+ // scroll-margin, and the scroll container's scroll-padding.
1338+ target.scrollIntoView({
1339+ // Only scroll the nearest scroll container.
1340+ container: 'nearest' ,
1341+ behavior: 'smooth'
1342+ });
1343+ });
1344+ </script>
1345+ </code></pre>
1346+ </div>
1347+
13121348The <dfn method for=Element lt="scroll(options)|scroll(x, y)">scroll()</dfn> method must run these steps:
13131349
131413501. If invoked with one argument, follow these substeps:
0 commit comments