anchor-scroll-update-003.html (1758B)
1 <!DOCTYPE html> 2 <html class="reftest-wait"> 3 <title>Anchored elements should update location on anchor's `anchor-name` property changes</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 #inner-anchored { 36 color: green; 37 position: absolute; 38 left: anchor(left); 39 bottom: anchor(top); 40 position-anchor: --anchor; 41 } 42 43 #outer-anchored { 44 color: yellow; 45 position: absolute; 46 left: anchor(left); 47 top: anchor(bottom); 48 position-anchor: --anchor; 49 } 50 </style> 51 52 <div style="position: relative"> 53 <div id="scroll-container"> 54 <div id="scroll-contents"> 55 <div id="placefiller-above-anchor"></div> 56 <div id="placefiller-before-anchor"></div> 57 <span id="anchor">anchor</span> 58 <div id="inner-anchored">inner-anchored</div> 59 </div> 60 </div> 61 <div id="outer-anchored">outer-anchored</div> 62 </div> 63 64 <script> 65 const scroller = document.getElementById('scroll-container'); 66 scroller.scrollTop = 300; 67 scroller.scrollLeft = 450; 68 69 function raf() { 70 return new Promise(resolve => requestAnimationFrame(resolve)); 71 } 72 73 async function runTest() { 74 await raf(); 75 await raf(); 76 document.getElementById('anchor').style.anchorName = '--anchor'; 77 document.documentElement.classList.remove('reftest-wait'); 78 } 79 runTest(); 80 </script> 81 </html>