blob: 296680341703b9efcb6bc7d5e15a1f09dcaf5074 [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that the intersection ratio is correctly computed when the
| root element clips overflow and 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>
div {
margin: 50px;
}
#root {
background-color: red;
padding: 5px;
border: solid black 10px;
width: 200px;
height: 200px;
position: absolute;
overflow: hidden;
}
#other {
background-color: blue;
width: 200px;
height: 200px;
position: absolute;
}
#target {
background-color: rgba(0, 128, 0, 0);
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div id="root">
<div id="other">
<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.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: 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>