1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
<!DOCTYPE html>
<html class="reftest-wait">
<meta charset="utf-8">
<link rel=author href="mailto:xiaochengh@chromium.org">
<link rel=help href="https://open-ui.org/components/popover.research.explainer">
<link rel=help href="https://html.spec.whatwg.org/multipage/popover.html">
<link rel=match href="popover-anchor-scroll-display-ref.html">
<div class=spacer style="height: 200px"></div>
<p>There should be a green box attached to the right side of each orange box.</p>
<!-- Example using the `anchor` implicit reference element -->
<div class=ex>
<div class=anchor id=anchor1></div>
<div id=popover1 popover=manual anchor=anchor1></div>
</div>
<!-- Example using a default anchor that is not the implicit anchor -->
<div class=ex>
<div class=anchor id=anchor2></div>
<div id=popover2 popover=manual anchor=fake-anchor></div>
</div>
<!-- Example using an implicit anchor that is not the default anchor -->
<div class=ex>
<div class=anchor id=anchor3></div>
<div id=popover3 popover=manual anchor=anchor3></div>
</div>
<!-- A position:fixed fake anchor. Any popover anchored to it won't move when
the document is scrolled. -->
<div id=fake-anchor></div>
<div class=spacer style="height: 200vh"></div>
<style>
.ex {
margin: 25px;
}
.ex div {
width: 100px;
height: 100px;
}
.anchor {
background: orange;
}
[popover] {
background: lime;
padding:0;
border:0;
}
#popover1 {
left: anchor(right);
top: anchor(top);
}
#fake-anchor {
position: fixed;
anchor-name: --fake-anchor;
}
#anchor2 {
anchor-name: --anchor2;
}
#popover2 {
anchor-default: --anchor2;
left: anchor(right);
top: anchor(top);
anchor-scroll: default;
}
#popover3 {
anchor-default: --fake-anchor;
left: anchor(implicit right);
top: anchor(implicit top);
anchor-scroll: implicit;
}
</style>
<script>
function raf() {
return new Promise(resolve => requestAnimationFrame(resolve));
}
async function runTest() {
document.querySelectorAll('[popover]').forEach(
popover => popover.showPopover());
// Render a frame at the intial scroll position.
await raf();
await raf();
document.documentElement.scrollTop = 100;
document.documentElement.classList.remove('reftest-wait');
// The popover should still be attached to the anchor.
}
runTest();
</script>
</html>
|