OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <div style="width:100%;height:700px;"></div> |
| 3 <div id="root" style="display: inline-block; overflow-y: scroll; height: 200px;"
> |
| 4 <div style="width:100px; height: 300px;"></div> |
| 5 <div id="target" style="width:100px; height:100px"></div> |
| 6 </div> |
| 7 <div style="width:100%;height:700px;"></div> |
| 8 |
| 9 <script src="../resources/js-test.js"></script> |
| 10 <script src="helper-functions.js"></script> |
| 11 <script> |
| 12 description("Simple intersection observer test with explicit root and target i
n the same document."); |
| 13 var target = document.getElementById("target"); |
| 14 var root = document.getElementById("root"); |
| 15 var entries = []; |
| 16 |
| 17 observer_callback = function(changes) { |
| 18 for (var i in changes) |
| 19 entries.push(changes[i]); |
| 20 }; |
| 21 var observer = new IntersectionObserver(observer_callback, {"root": document.g
etElementById("root")}); |
| 22 observer.observe(target); |
| 23 |
| 24 // Test that notifications are not generated when the target is overflow clipp
ed by the root. |
| 25 var expected0 = []; |
| 26 function step0() { |
| 27 setTimeout(function() { |
| 28 checkResults(expected0, "entries"); |
| 29 document.scrollingElement.scrollTop = 600; |
| 30 requestAnimationFrame(step1); |
| 31 }); |
| 32 } |
| 33 |
| 34 var expected1 = []; |
| 35 function step1() { |
| 36 setTimeout(function() { |
| 37 checkResults(expected1, "entries"); |
| 38 checkResults([], "entries"); |
| 39 root.scrollTop = 150; |
| 40 requestAnimationFrame(step2); |
| 41 }); |
| 42 } |
| 43 |
| 44 var expected2 = [ |
| 45 { |
| 46 'boundingClientRect': [ 8, 108, 258, 358 ], |
| 47 'intersectionRect': [ 8, 108, 258, 308 ], |
| 48 'rootBounds' : [ 8, 108, 108, 308 ], |
| 49 'target': target |
| 50 } |
| 51 ]; |
| 52 function step2() { |
| 53 setTimeout(function() { |
| 54 checkResults(expected2, "entries"); |
| 55 document.scrollingElement.scrollTop = 0; |
| 56 requestAnimationFrame(step3); |
| 57 }); |
| 58 } |
| 59 |
| 60 var expected3 = expected2; |
| 61 function step3() { |
| 62 setTimeout(function() { |
| 63 checkResults(expected3, "entries", 1); |
| 64 root.scrollTop = 0; |
| 65 requestAnimationFrame(step4); |
| 66 }); |
| 67 } |
| 68 |
| 69 var expected4 = Array.prototype.concat(expected3, [ |
| 70 { |
| 71 'boundingClientRect': [ 8, 108, 1008, 1108 ], |
| 72 'intersectionRect': [ 0, 0, 0, 0 ], |
| 73 'rootBounds' : [ 8, 108, 708, 908 ], |
| 74 'target': target |
| 75 } |
| 76 ]); |
| 77 function step4() { |
| 78 setTimeout(function() { |
| 79 checkResults(expected4, "entries", 1); |
| 80 root.scrollTop = 150; |
| 81 requestAnimationFrame(step5); |
| 82 }); |
| 83 } |
| 84 |
| 85 // This tests that notifications are generated even when the root element is o
ff screen. |
| 86 var expected5 = Array.prototype.concat(expected4, [ |
| 87 { |
| 88 'boundingClientRect': [ 8, 108, 858, 958 ], |
| 89 'intersectionRect': [ 8, 108, 858, 908 ], |
| 90 'rootBounds' : [ 8, 108, 708, 908 ], |
| 91 'target': target |
| 92 } |
| 93 ]); |
| 94 function step5() { |
| 95 setTimeout(function() { |
| 96 checkResults(expected5, "entries", 2); |
| 97 finishTest(); |
| 98 }); |
| 99 } |
| 100 |
| 101 requestAnimationFrame(step0); |
| 102 </script> |
OLD | NEW |