| <!DOCTYPE html> | |
| <!-- | |
| | This test checks that the intersection ratio is correctly computed if the | |
| | root element has nonzero padding and border. | |
| | The target element is initially transparent, but if the intersection ratio is | |
| | computed correctly it turns opaque (becomes visibly green). | |
| | https://www.w3.org/TR/intersection-observer/ | |
| --> | |
| <html> | |
| <head> | |
| <style> | |
| #root { | |
| background-color: red; | |
| padding: 5px; | |
| border: solid black 5px; | |
| width: 300px; | |
| height: 200px; | |
| position: absolute; | |
| } | |
| #target { | |
| background-color: rgba(0, 128, 0, 0); | |
| width: 200px; | |
| height: 100px; | |
| margin: 150px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="root"> | |
| <div id="target"></div> | |
| </div> | |
| <script> | |
| if (window.testRunner) { | |
| window.testRunner.waitUntilDone(); | |
| } | |
| window.addEventListener("load", function() { | |
| var rootElement = document.querySelector('#root'); | |
| var targetElement = document.querySelector('#target'); | |
| var expectedRatio = 0.48; | |
| var epsilon = 0.00001; | |
| function handleIntersect(entries, observer) { | |
| entries.forEach(function(entry) { | |
| console.log(entry.intersectionRatio); | |
| if (Math.abs(entry.intersectionRatio - expectedRatio) < epsilon) { | |
| entry.target.style.backgroundColor = "rgba(0, 128, 0, 255)"; | |
| } | |
| }); | |
| } | |
| function createObserver() { | |
| var options = { | |
| root: rootElement, | |
| rootMargin: "0px", | |
| threshold: 0.0 | |
| }; | |
| var observer = new IntersectionObserver(handleIntersect, options); | |
| observer.observe(targetElement); | |
| } | |
| createObserver(); | |
| if (window.testRunner) { | |
| window.testRunner.DoNonMeasuredLayout(); | |
| window.setTimeout(function() { window.testRunner.notifyDone(); }, 0); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |