blob: 81a92d459725168253a92c77c73331428b4b7fe0 [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that an intersection is observed when the target element has
| zero area but technically intersects with the root element.
| The root element is initially red, but if the intersection is observed, as is
| expected, it becomes green.
| https://www.w3.org/TR/intersection-observer/
-->
<html>
<head>
<style>
#root {
background-color: red;
width: 200px;
height: 200px;
position: absolute;
}
#target {
width: 100px;
height: 0px;
position: absolute;
margin: 50px;
}
</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');
function handleIntersect(entries, observer) {
entries.forEach(function(entry) {
console.log(entry.isIntersecting);
if (entry.isIntersecting) {
rootElement.style.backgroundColor = "green";
}
});
}
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>