simple-effects.html (2034B)
1 <!DOCTYPE html> 2 <meta name="viewport" content="width=device-width,initial-scale=1"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="../resources/intersection-observer-test-utils.js"></script> 6 7 <style> 8 body, html { 9 margin: 0; 10 } 11 pre, #log { 12 position: absolute; 13 top: 0; 14 left: 200px; 15 } 16 #target { 17 width: 100px; 18 height: 100px; 19 background-color: green; 20 } 21 #effects { 22 opacity: 1; 23 filter: none; 24 } 25 </style> 26 27 <div id="effects"> 28 <div id="target"></div> 29 </div> 30 31 <script> 32 var delay = 100; 33 var entries = []; 34 var target; 35 var effects; 36 37 runTestCycle(function() { 38 target = document.getElementById("target"); 39 effects = document.getElementById("effects"); 40 assert_true(!!target, "target exists"); 41 assert_true(!!effects, "effects exists"); 42 var observer = new IntersectionObserver(function(changes) { 43 entries = entries.concat(changes) 44 }, {trackVisibility: true, delay: delay}); 45 observer.observe(target); 46 entries = entries.concat(observer.takeRecords()); 47 assert_equals(entries.length, 0, "No initial notifications."); 48 runTestCycle(step0, "First rAF.", delay); 49 }, "IntersectionObserverV2 in a single document using the implicit root, with a non-zero opacity ancestor.", delay); 50 51 function step0() { 52 effects.style.opacity = "0.99"; 53 runTestCycle(step1, "effects.style.opacity = 0.99", delay); 54 checkLastEntry(entries, 0, [0, 100, 0, 100, 0, 100, 0, 100, 0, 800, 0, 600, true, true]); 55 } 56 57 function step1() { 58 effects.style.opacity = "1"; 59 runTestCycle(step2, "effects.style.opacity = 1", delay); 60 checkLastEntry(entries, 1, [0, 100, 0, 100, 0, 100, 0, 100, 0, 800, 0, 600, true, false]); 61 } 62 63 function step2() { 64 effects.style.filter = "grayscale(50%)"; 65 runTestCycle(step3, "effects.style.filter = grayscale(50%)", delay); 66 checkLastEntry(entries, 2, [0, 100, 0, 100, 0, 100, 0, 100, 0, 800, 0, 600, true, true]); 67 } 68 69 function step3() { 70 checkLastEntry(entries, 3, [0, 100, 0, 100, 0, 100, 0, 100, 0, 800, 0, 600, true, false]); 71 } 72 </script>