OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script> | 2 <script> |
3 if (window.internals) { | 3 if (window.internals) { |
4 internals.settings.setCSSStickyPositionEnabled(true); | 4 internals.settings.setCSSStickyPositionEnabled(true); |
5 } | 5 } |
6 </script> | 6 </script> |
7 <style type="text/css"> | 7 |
8 div { | 8 <html> |
9 height: 100px; | 9 <head> |
10 width: 100px; | 10 <style> |
11 } | 11 body { |
12 .spacer { | 12 margin: 0; |
13 background-color: red; | 13 height: 2000px; |
14 } | 14 overflow: hidden; /* hide scrollbars */ |
15 .sticky { | 15 } |
16 background-color: green; | 16 |
17 position: sticky; | 17 .group { |
18 } | 18 display: inline-block; |
19 .absoffset { | 19 position: relative; |
20 background-color: green; | 20 width: 250px; |
21 position: absolute; | 21 height: 500px; |
22 top: -100px; | 22 } |
23 } | 23 |
| 24 .container { |
| 25 width: 200px; |
| 26 height: 400px; |
| 27 outline: 2px solid black; |
| 28 } |
| 29 |
| 30 .box { |
| 31 width: 200px; |
| 32 height: 200px; |
| 33 } |
| 34 |
| 35 .sticky { |
| 36 position: sticky; |
| 37 top: 100px; |
| 38 background-color: silver; |
| 39 } |
| 40 |
| 41 .child { |
| 42 position: absolute; |
| 43 background-color: green; |
| 44 top: 50px; |
| 45 left: 50px; |
| 46 } |
| 47 |
| 48 .indicator { |
| 49 position: absolute; |
| 50 top: 250px; |
| 51 left: 50px; |
| 52 background-color: red; |
| 53 } |
24 </style> | 54 </style> |
25 <div class="spacer"></div> | 55 <script> |
26 <div class="sticky"> | 56 function doTest() |
27 <!-- | 57 { |
28 Tests that the absolute positioned child is positioned relative to the stick
y container. You should see only a | 58 window.scrollTo(0, 100); |
29 green box as this will cover up the red box above the sticky div. | 59 } |
30 --> | 60 window.addEventListener('load', doTest, false); |
31 <div class="absoffset"></div> | 61 </script> |
32 </div> | 62 </head> |
| 63 <body> |
| 64 <div class="group"> |
| 65 <div class="indicator box"></div> |
| 66 <div class="container"> |
| 67 <div class="sticky box"> |
| 68 <div class="child box"></div> |
| 69 </div> |
| 70 </div> |
| 71 </div> |
| 72 |
| 73 </body> |
| 74 </html> |
OLD | NEW |