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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
<!DOCTYPE html>
<html>
<head>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/common.js" ></script>
</head>
<body>
<style>
.scroller {
overflow: scroll;
position: relative;
height: 400px;
width: 400px;
border:solid 1px black;
scroll-snap-type: y mandatory;
}
.no-snap { scroll-snap-align: none }
.scroller div:focus {
border: solid 1px red;
}
.large-space {
height: 300vh;
width: 300vw;
position: absolute;
}
.target {
scroll-snap-align: start;
position: absolute;
width: 100px;
height: 100px;
border: solid 1px black;
}
.top {
top: 0px;
}
.left {
left: 0px;
}
.right {
left: 200px;
}
.bottom {
top: 200px;
}
.inner {
text-align: right;
}
.inner1 {
height: 150px;
width: 150px;
top: 150px;
left: 100px;
background-color: blue;
}
.inner2 {
height: 100px;
width: 100px;
top: 150px;
left: 100px;
background-color: pink;
}
.inner3 {
height: 75px;
width: 75px;
top: 150px;
left: 100px;
background-color: green;
}
.inner4 {
height: 50px;
width: 50px;
top: 150px;
left: 100px;
background-color: grey;
}
.outer {
height: 200px;
width: 200px;
top: 150px;
left: 50px;
left: 50px;
background-color: yellow;
}
</style>
<div id="scroller" class="scroller">
<div class="large-space"></div>
<div class="top left target">Top Left</div>
<div class="top right target">Top Right</div>
<div class="outer target" id="outer">Outer</div>
<div class="inner inner1 target" id="inner1">I1</div>
<div class="inner inner2 target" id="inner2">I2</div>
<div class="inner inner3 target" id="inner3">I3</div>
<div class="inner inner4 target" id="inner4">I4</div>
</div>
<script>
function cleanup() {
inner.style.top = 100;
outer.style.top = 100;
}
window.onload = (async () => {
const inner1 = document.getElementById("inner1");
const inner2 = document.getElementById("inner2");
const inner3 = document.getElementById("inner3");
const inner4 = document.getElementById("inner4");
const outer = document.getElementById("outer");
const scroller = document.getElementById("scroller");
promise_test(async (t) => {
await waitForCompositorCommit();
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[],
/*aligned_elements_y=*/[inner1, inner2, inner3, inner4, outer],
/*axis=*/"y",
/*expected_target_x*/null,
/*expected_target_y*/inner4);
// Push inner4 outside the snapport. It should no longer be considered
// the snap target; inner3 is next in line.
inner4.style.left = "500px";
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[],
/*aligned_elements_y=*/[inner1, inner2, inner3, inner4, outer],
/*axis=*/"y",
/*expected_target_x*/null,
/*expected_target_y*/inner3);
// Reset inner4's style.
inner4.style.left = "100px";
}, "snap container selects innermost area as snap target");
promise_test(async (t) => {
t.add_cleanup(() => {
outer.style.top = "150px";
});
await waitForCompositorCommit();
// Move outer target below inner targets.
outer.style.top = "400px";
// Snap to now-below outer target.
scroller.scrollTop = outer.offsetTop;
runLayoutSnapSeletionVerificationTest(t, scroller,
[inner1, inner2, inner3, inner4], outer, "y");
}, "snap container follows selected snap target after layout change " +
"(the pre-existing snap target should not be overriden because of " +
"the innermost area)");
});
</script>
</body>
</html>
|