| <!DOCTYPE html> |
| <!-- |
| | This test checks that an IntersectionObserverEntry's |isIntersecting| |
| | property is set to false if its |intersectionRatio| > 0 but |
| | |intersectionRatio| < all of the IntersectionObserver's threshold values. |
| | The target element is initially yellow, and only turns blue if the |
| | IntersectionObserver correctly computes the |isIntersecting| and |
| | |intersectionRatio| fields as described above. |
| | https://www.w3.org/TR/intersection-observer/ |
| --> |
| <html> |
| <head> |
| <style> |
| #target { |
| background-color: yellow; |
| width: 200px; |
| height: 150px; |
| position: absolute; |
| left: -100px; |
| top: -75px; |
| } |
| </style> |
| </head> |
| <body> |
| <div> |
| <div id="target"> |
| </div> |
| </div> |
| |
| <script> |
| if (window.testRunner) { |
| window.testRunner.waitUntilDone(); |
| } |
| |
| window.addEventListener("load", function() { |
| var targetElement = document.querySelector('#target'); |
| var expectedRatio = 0.25; |
| |
| function handleIntersect(entries, observer) { |
| entries.forEach(function(entry) { |
| console.log(entry.intersectionRatio); |
| if (entry.intersectionRatio == expectedRatio && !entry.isIntersecting) { |
| entry.target.style.backgroundColor = "blue"; |
| } |
| }); |
| } |
| |
| function createObserver() { |
| var options = { |
| root: null, |
| rootMargin: "0px", |
| threshold: 0.5 |
| }; |
| |
| 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> |