blob: 56bb743381151cecb3850cd24c194795c1fa2ab2 [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that the intersection ratio is correctly computed when the
| root is set to the implicit root.
| 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>
#target {
background-color: rgba(0, 128, 0, 0);
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.target.style.backgroundColor = "rgba(0, 128, 0, 255)";
}
});
}
function createObserver() {
var options = {
root: null,
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>