OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <div style="width:100%;height:700px;"></div> |
| 3 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> |
| 4 <div style="width:100%; height:700px;"></div> |
| 5 |
| 6 <script src="../resources/js-test.js"></script> |
| 7 <script src="helper-functions.js"></script> |
| 8 <script> |
| 9 description("Simple intersection observer test with no explicit root and one d
ocument."); |
| 10 var target = document.getElementById("target"); |
| 11 var entries = []; |
| 12 |
| 13 observer_callback = function(changes) { |
| 14 for (var i in changes) |
| 15 entries.push(changes[i]); |
| 16 }; |
| 17 var observer = new IntersectionObserver(observer_callback, {}); |
| 18 observer.observe(target); |
| 19 |
| 20 // TODO: It shouldn't be necessary to RAF after the call to observer() |
| 21 // and before changing the scroll position, but it is. |
| 22 |
| 23 var expected0 = []; |
| 24 function step0() { |
| 25 setTimeout(function() { |
| 26 checkResults(expected0, "entries"); |
| 27 document.scrollingElement.scrollTop = 300; |
| 28 requestAnimationFrame(step1); |
| 29 }); |
| 30 } |
| 31 |
| 32 var expected1 = [ |
| 33 { |
| 34 'boundingClientRect': [ 8, 108, 408, 508 ], |
| 35 'intersectionRect': [ 8, 108, 408, 508 ], |
| 36 'rootBounds' : [ 0, 785, 0, 600 ], |
| 37 'target': target |
| 38 }, |
| 39 ]; |
| 40 function step1() { |
| 41 setTimeout(function() { |
| 42 checkResults(expected1, "entries"); |
| 43 document.scrollingElement.scrollTop = 100; |
| 44 requestAnimationFrame(step2); |
| 45 }); |
| 46 } |
| 47 |
| 48 var expected2 = expected1.concat([ |
| 49 { |
| 50 'boundingClientRect': [ 8, 108, 608, 708 ], |
| 51 'intersectionRect': [ 0, 0, 0, 0 ], |
| 52 'rootBounds' : [ 0, 785, 0, 600 ], |
| 53 'target': target |
| 54 } |
| 55 ]); |
| 56 function step2() { |
| 57 setTimeout(function() { |
| 58 checkResults(expected2, "entries", 1); |
| 59 finishTest(); |
| 60 document.scrollingElement.scrollTop = 0; |
| 61 }); |
| 62 } |
| 63 |
| 64 requestAnimationFrame(step0); |
| 65 </script> |
OLD | NEW |