anchor-scroll-update-001.html (1725B)
1 <!DOCTYPE html> 2 <html class="reftest-wait"> 3 <title>Anchored elements should keep "pinned" to the anchor during scroll updates</title> 4 <link rel="author" href="mailto:xiaochengh@chromium.org"> 5 <link rel="help" href="https://drafts.csswg.org/css-anchor-1/"> 6 <link rel="match" href="reference/anchor-scroll-ref.html"> 7 <link rel="stylesheet" href="/fonts/ahem.css"> 8 <style> 9 body { 10 font: 20px/1 Ahem; 11 margin: 0; 12 } 13 14 #scroll-container { 15 width: 400px; 16 height: 400px; 17 overflow: scroll; 18 } 19 20 #scroll-contents { 21 width: 1000px; 22 height: 1000px; 23 position: relative; 24 } 25 26 #placefiller-above-anchor { 27 height: 500px; 28 } 29 30 #placefiller-before-anchor { 31 display: inline-block; 32 width: 500px; 33 } 34 35 #anchor { 36 anchor-name: --anchor; 37 } 38 39 #inner-anchored { 40 color: green; 41 position: absolute; 42 left: anchor(left); 43 bottom: anchor(top); 44 position-anchor: --anchor; 45 } 46 47 #outer-anchored { 48 color: yellow; 49 position: absolute; 50 left: anchor(left); 51 top: anchor(bottom); 52 position-anchor: --anchor; 53 } 54 </style> 55 56 <div style="position: relative"> 57 <div id="scroll-container"> 58 <div id="scroll-contents"> 59 <div id="placefiller-above-anchor"></div> 60 <div id="placefiller-before-anchor"></div> 61 <span id="anchor">anchor</span> 62 <div id="inner-anchored">inner-anchored</div> 63 </div> 64 </div> 65 <div id="outer-anchored">outer-anchored</div> 66 </div> 67 68 <script> 69 function raf() { 70 return new Promise(resolve => requestAnimationFrame(resolve)); 71 } 72 73 async function runTest() { 74 await raf(); 75 await raf(); 76 const scroller = document.getElementById('scroll-container'); 77 scroller.scrollTop = 300; 78 scroller.scrollLeft = 450; 79 document.documentElement.classList.remove('reftest-wait'); 80 } 81 runTest(); 82 </script> 83 </html>