OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/js-test.js"></script> |
3 <script src="helper-functions.js"></script> | 3 <script src="helper-functions.js"></script> |
4 <div style="width:100%; height:700px;"></div> | 4 <div style="width:100%; height:700px;"></div> |
5 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> | 5 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> |
6 <div style="width:100%; height:700px;"></div> | 6 <div style="width:100%; height:700px;"></div> |
7 | 7 |
8 <script> | 8 <script> |
9 description("Intersection observer test with multiple thresholds."); | 9 description("Intersection observer test with multiple thresholds."); |
10 var target = document.getElementById("target"); | 10 var target = document.getElementById("target"); |
11 var entries = []; | 11 var entries = []; |
12 | 12 |
13 observer_callback = function(changes) { | 13 observer_callback = function(changes) { |
14 for (var i in changes) | 14 for (var i in changes) |
15 entries.push(changes[i]); | 15 entries.push(changes[i]); |
16 }; | 16 }; |
17 var observer = new IntersectionObserver(observer_callback, { | 17 var observer = new IntersectionObserver(observer_callback, { |
18 threshold: [0, 0.25, 0.5, 0.75] | 18 threshold: [0, 0.25, 0.5, 0.75] |
19 }); | 19 }); |
20 observer.observe(target); | 20 observer.observe(target); |
21 | 21 |
22 // TODO(szager): It shouldn't be necessary to RAF after the call to observer() | |
23 // and before changing the scroll position, but it is. | |
24 | |
25 function step0() { | 22 function step0() { |
26 setTimeout(function() { | 23 setTimeout(function() { |
27 shouldBeEqualToNumber("entries.length", 0); | 24 shouldBeEqualToNumber("entries.length", 0); |
28 document.scrollingElement.scrollTop = 120; | 25 document.scrollingElement.scrollTop = 120; |
29 requestAnimationFrame(step1); | 26 requestAnimationFrame(step1); |
30 }); | 27 }); |
31 } | 28 } |
32 | 29 |
33 function step1() { | 30 function step1() { |
34 setTimeout(function() { | 31 setTimeout(function() { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 shouldBeEqualToNumber("entries[6].intersectionRect.bottom", 0); | 174 shouldBeEqualToNumber("entries[6].intersectionRect.bottom", 0); |
178 shouldBeEqualToNumber("entries[6].rootBounds.left", 0); | 175 shouldBeEqualToNumber("entries[6].rootBounds.left", 0); |
179 shouldBeEqualToNumber("entries[6].rootBounds.right", 785); | 176 shouldBeEqualToNumber("entries[6].rootBounds.right", 785); |
180 shouldBeEqualToNumber("entries[6].rootBounds.top", 0); | 177 shouldBeEqualToNumber("entries[6].rootBounds.top", 0); |
181 shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600); | 178 shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600); |
182 shouldEvaluateToSameObject("entries[6].target", target); | 179 shouldEvaluateToSameObject("entries[6].target", target); |
183 finishTest(); | 180 finishTest(); |
184 document.scrollingElement.scrollTop = 0; | 181 document.scrollingElement.scrollTop = 0; |
185 }); | 182 }); |
186 } | 183 } |
187 requestAnimationFrame(step0); | 184 |
| 185 step0(); |
188 </script> | 186 </script> |
OLD | NEW |