anchor-scroll-chained-001-ref.html (576B)
1 <!DOCTYPE html> 2 <style> 3 body { 4 margin: 0; 5 } 6 7 div { 8 width: 100px; 9 height: 100px; 10 } 11 12 #scroller { 13 overflow: scroll; 14 } 15 16 #anchor { 17 height: 20px; 18 background: orange; 19 } 20 21 #anchored1 { 22 position: absolute; 23 top: 50px; 24 left: 0; 25 background: green; 26 } 27 28 #anchored2 { 29 position: absolute; 30 top: 150px; 31 left: 0; 32 background: lime; 33 } 34 35 </style> 36 37 <div id="scroller"> 38 <div style="height: 230px"></div> 39 <div id="anchor"></div> 40 <div style="height: 230px"></div> 41 </div> 42 <div id="anchored1"></div> 43 <div id="anchored2"></div> 44 45 <script> 46 scroller.scrollTop = 200; 47 </script>