svg-intersection-with-fractional-bounds-2.html (2475B)
1 <!DOCTYPE html> 2 <title>IntersectionObserver observing an SVG <rect> with fractional bounds element</title> 3 <meta name="viewport" content="width=device-width,initial-scale=1"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/intersection-observer-test-utils.js"></script> 7 8 <svg id="container" width="1" height="1" viewBox="0 0 1000 1000" style="background: lightblue; position: absolute; top: 0; left: 0;"> 9 <rect id="target" x="0" y="-3" width="4" height="4" fill="green"></rect> 10 </svg> 11 12 <script> 13 setup(() => { 14 window.entries = []; 15 window.target = document.getElementById("target"); 16 window.targetRect = target.getBoundingClientRect(); 17 }); 18 var epsilon = 0.0001; 19 runTestCycle(function() { 20 assert_true(!!target, "target exists"); 21 var observer = new IntersectionObserver(changes => { 22 entries = entries.concat(changes); 23 }, {root: container, threshold: [0, 0.25, 0.5, 0.7, 1]}); 24 observer.observe(target); 25 entries = entries.concat(observer.takeRecords()); 26 assert_equals(entries.length, 0, "No initial notifications"); 27 runTestCycle(step0, "Initial Observation"); 28 }); 29 function step0() { 30 target.setAttribute('y', -2); 31 runTestCycle(step1, "Changing target y position to -2 (-0.002 in root coordinates)"); 32 checkLastEntry(entries, 0, [ 33 0, 0.004, -0.003, 0.001, 34 0, 0.004, 0, 0.001, 35 0, 1, 0, 1, 36 true, 37 ], epsilon); 38 } 39 function step1() { 40 target.setAttribute('y', -1); 41 runTestCycle(step2, "Changing target y position to -1 (-0.001 in root coordinates)"); 42 checkLastEntry(entries, 1, [ 43 0, 0.004, -0.002, 0.002, 44 0, 0.004, 0, 0.002, 45 0, 1, 0, 1, 46 true, 47 ], epsilon); 48 } 49 function step2() { 50 target.setAttribute('y', -4); 51 runTestCycle(step3, "Changing target y position to -4 (-0.004 in root coordinates)"); 52 checkLastEntry(entries, 2, [ 53 0, 0.004, -0.001, 0.003, 54 0, 0.004, 0, 0.003, 55 0, 1, 0, 1, 56 true, 57 ], epsilon); 58 } 59 function step3() { 60 target.setAttribute('y', 0); 61 runTestCycle(step4, "Changing target y position to 0"); 62 checkLastEntry(entries, 3, [ 63 0, 0.004, -0.004, 0, 64 0, 0.004, 0, 0, 65 0, 1, 0, 1, 66 true, 67 ], epsilon); 68 } 69 function step4() { 70 checkLastEntry(entries, 4, [ 71 0, 0.004, 0, 0.004, 72 0, 0.004, 0, 0.004, 73 0, 1, 0, 1, 74 true, 75 ], epsilon); 76 } 77 </script>