blob: fe1d0b8df47eb3f3fe6d066cff70e59c7a806a87 [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that two elements that appear to intersect, but are not in
| the same containing block chain, should not be considered to intersect,
| The root is red and the target is blue; if an intersection is observed, then
| the target turns green (this should not occur).
| https://www.w3.org/TR/intersection-observer/
-->
<html>
<head>
<style>
#root {
background-color: red;
width: 200px;
height: 100px;
position: absolute;
}
#target {
background-color: blue;
width: 50px;
height: 150px;
position: fixed;
margin: 25px;
}
</style>
</head>
<body>
<div id="root">
<div id="element">
<div id="target"></div>
</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;
function handleIntersect(entries, observer) {
entries.forEach(function(entry) {
console.log(entry.intersectionRatio);
if (entry.intersectionRatio > expectedRatio) {
entry.target.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>