OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../../../resources/testharness.js"></script> | |
3 <script src="../../../resources/testharnessreport.js"></script> | |
4 <style> | |
5 body { | |
6 margin: 0; | |
7 } | |
8 | |
9 .paddingBefore { | |
10 height: 150px; | |
11 } | |
12 | |
13 #scroller { | |
14 height: 100px; | |
15 width: 200px; | |
16 overflow-y: scroll; | |
17 } | |
18 | |
19 .paddingAfter { | |
20 height: 500px; | |
21 } | |
22 | |
23 #sticky { | |
24 height: 50px; | |
25 position: sticky; | |
26 top: 20px; | |
27 } | |
28 </style> | |
29 | |
30 <div id="scroller"> | |
31 <div class="paddingBefore"></div> | |
32 <div id="sticky"></div> | |
33 <div class="paddingAfter"></div> | |
34 </div> | |
35 | |
36 <script> | |
37 if (window.internals) { | |
38 internals.settings.setCSSStickyPositionEnabled(true); | |
39 } | |
40 | |
41 // These tests currently mimic the behavior of Firefox for the interaction | |
42 // between scrollIntoView() and position:sticky, where the offset location of | |
43 // the sticky element is used to determine how far to scroll. This means that | |
44 // scrollIntoView() may scroll even when the sticky is already 'in view', and | |
45 // attempts to scroll so that the offset position of the sticky is at the top | |
46 // of the screen. | |
47 // | |
48 // TODO(smcgruer): Update tests once http://crbug.com/664246 is resolved. | |
49 | |
50 test(function() { | |
51 var scroller = document.getElementById('scroller'); | |
52 var sticky = document.getElementById('sticky'); | |
53 scroller.scrollTop = 0; | |
54 sticky.scrollIntoView(); | |
flackr
2017/01/24 20:22:28
Did we need to change layout before scrolling into
smcgruer
2017/01/24 22:20:01
Probably a good idea, done.
| |
55 assert_equals(scroller.scrollTop, 150); | |
56 }, "scrollIntoView should scroll when sticky is not visible"); | |
57 | |
58 test(function() { | |
59 var scroller = document.getElementById('scroller'); | |
60 var sticky = document.getElementById('sticky'); | |
61 scroller.scrollTop = 150; | |
62 sticky.scrollIntoView(); | |
63 assert_equals(scroller.scrollTop, 170); | |
64 }, "scrollIntoView should scroll when sticky is already in view"); | |
65 | |
66 test(function() { | |
67 var scroller = document.getElementById('scroller'); | |
68 var sticky = document.getElementById('sticky'); | |
69 scroller.scrollTop = 0; | |
70 sticky.scrollIntoViewIfNeeded(); | |
71 assert_equals(scroller.scrollTop, 125); | |
72 }, "scrollIntoViewIfNeeded should scroll when sticky is not visible"); | |
73 | |
74 test(function() { | |
75 var scroller = document.getElementById('scroller'); | |
76 var sticky = document.getElementById('sticky'); | |
77 scroller.scrollTop = 150; | |
78 sticky.scrollIntoViewIfNeeded(); | |
79 assert_equals(scroller.scrollTop, 150); | |
80 }, "scrollIntoViewIfNeeded should not scroll when sticky is already in view"); | |
81 </script> | |
OLD | NEW |