blob: 4222fddf9f97f9b652cfad208c8f70915429a8cd [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that the intersection ratio is properly computed when one of
| the containing blocks 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>
#root {
background-color: red;
width: 200px;
height: 300px;
position: absolute;
}
#element {
background-color: blue;
width: 200px;
height: 100px;
position: absolute;
margin: 100px;
padding: 5px;
border: 10px solid;
overflow: hidden;
}
#target {
background-color: rgba(0, 128, 0, 0);
width: 100px;
height: 100px;
position: absolute;
margin: 50px;
}
</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.1925;
var epsilon = 0.00001;
function handleIntersect(entries, observer) {
entries.forEach(function(entry) {
console.log(entry);
if (Math.abs(entry.intersectionRatio - expectedRatio) < epsilon) {
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>