blob: 12cd03439b774698304fefdaa2c1f26faf3671a5 [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that the root margin is being parsed and factored in
| appropriately.
| 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 {
position: absolute;
}
#root {
background-color: red;
width: 250px;
height: 150px;
}
#target {
background-color: rgba(0, 128, 0, 0);
width: 150px;
height: 250px;
margin: 50px 150px;
}
</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');
var expectedRatio = 0.2816;
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: "40px -5% 20px",
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>