blob: 41f4e1c506cc7f2406dc587ae736b329c304b907 [file] [log] [blame]
<!DOCTYPE html>
<!--
| This test checks that intersection observer events get fired when
| intersection information changes as the result of an element in the
| containing block chain undergoing a transition.
| The target element is initially green when it intersects with the root
| element, but when it stops intersecting (as it should after the transition)
| it should turn yellow.
| https://www.w3.org/TR/intersection-observer/
-->
<html>
<head>
<style>
div {
margin: 50px;
}
#static {
background-color: red;
width: 200px;
height: 200px;
position: absolute;
}
#moving {
background-color: blue;
width: 200px;
height: 200px;
position: absolute;
transition: transform 1s linear;
}
#target {
background-color: green;
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div id="static">
<div id="moving">
<div id="target">
</div>
</div>
</div>
<script>
if (window.testRunner) {
window.testRunner.waitUntilDone();
}
window.addEventListener("load", function() {
var staticElement = document.querySelector('#static');
var movingElement = document.querySelector('#moving');
var targetElement = document.querySelector('#target');
function handleIntersect(entries, observer) {
entries.forEach(function(entry) {
console.log(entry.intersectionRatio);
if (entry.intersectionRatio == 0) {
entry.target.style.backgroundColor = "yellow";
}
});
}
function createObserver() {
var options = {
root: staticElement,
rootMargin: "0px",
threshold: 0.0
};
var observer = new IntersectionObserver(handleIntersect, options);
observer.observe(targetElement);
}
createObserver();
movingElement.style.transform = "translate(110px, 0)";
if (window.testRunner) {
window.testRunner.DoNonMeasuredLayout();
window.testRunner.AdvanceClockByMs(1000);
window.testRunner.DoNonMeasuredLayout();
window.setTimeout(function() { window.testRunner.notifyDone(); }, 0);
}
});
</script>
</body>
</html>