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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
<!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;
width: 350px;
height: 350px;
border: solid 1px black;
scroll-snap-type: both mandatory;
position: relative;
resize: both;
}
.large-space {
height: 300vh;
width: 300vw;
position: absolute;
}
.snap {
scroll-snap-align: start;
}
.box {
width: 100px;
height: 100px;
background-color: green;
position: absolute;
}
.leftcol {
left: 110px;
}
.midcol {
left: 220px;
}
.rightcol {
left: 330px;
}
.toprow {
top: 110px;
}
.midrow {
top: 220px;
}
.bottomrow {
top: 330px;
}
.placeholder {
position: absolute;
top: 0px;
left: 0px;
width: 10px;
height: 10px;
background-color: black;
scroll-snap-align: start;
}
</style>
<div class="scroller" id="scroller">
<div class="large-space"><div>
<div class="placeholder"></div>
<div id="box1" class="leftcol toprow snap box">Box 1</div>
<div id="box2" class="midcol toprow snap box">Box 2</div>
<div id="box3" class="rightcol toprow snap box">Box 3</div>
<div id="box4" class="leftcol midrow snap box">Box 4</div>
<div id="box5" class="midcol midrow snap box">Box 5</div>
<div id="box6" class="rightcol midrow snap box">Box 6</div>
<div id="box7" class="leftcol bottomrow snap box">Box 7</div>
<div id="box8" class="midcol bottomrow snap box">Box 8</div>
<div id="box9" class="rightcol bottomrow snap box">Box 9</div>
</div>
<script>
window.onload = () => {
// This test sets up a 3x3 grid within scroller:
// -------------------------
// | Box 1 | Box 2 | Box 3 |
// ------------------------
// | Box 4 | Box 5 | Box 6 |
// -------------------------
// | Box 7 | Box 8 | Box 9 |
// -------------------------
const scroller = document.getElementById("scroller");
const boxes = document.querySelectorAll(".snap.box");
function box(n) {
return boxes[n - 1];
}
promise_test(async (t) => {
await waitForCompositorCommit();
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(1), box(4), box(7)],
/*aligned_elements_y=*/[box(1), box(2), box(3)],
/*axis=*/ "both",
/*expected_target_x=*/box(1),
/*expected_target_y=*/box(1));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(1), box(4), box(7)],
/*aligned_elements_y=*/[box(4), box(5), box(6)],
/*axis=*/"both",
/*expected_target_x=*/box(4),
/*expected_target_y=*/box(4));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(1), box(4), box(7)],
/*aligned_elements_y=*/[box(7), box(8), box(9)],
/*axis=*/"both",
/*expected_target_x=*/box(7),
/*expected_target_y=*/box(7));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(2), box(5), box(8)],
/*aligned_elements_y=*/[box(1), box(2), box(3)],
/*axis=*/ "both",
/*expected_target_x=*/box(2),
/*expected_target_y=*/box(2));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(2), box(5), box(8)],
/*aligned_elements_y=*/[box(4), box(5), box(6)],
/*axis=*/"both",
/*expected_target_x=*/box(5),
/*expected_target_y=*/box(5));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(2), box(5), box(8)],
/*aligned_elements_y=*/[box(7), box(8), box(9)],
/*axis=*/"both",
/*expected_target_x=*/box(8),
/*expected_target_y=*/box(8));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(3), box(6), box(9)],
/*aligned_elements_y=*/[box(1), box(2), box(3)],
/*axis=*/ "both",
/*expected_target_x=*/box(3),
/*expected_target_y=*/box(3));
await runScrollSnapSelectionVerificationTest(t, scroller,
/*aligned_elements_x=*/[box(3), box(6), box(9)],
/*aligned_elements_y=*/[box(4), box(5), box(6)],
/*axis=*/"both",
/*expected_target_x=*/box(6),
/*expected_target_y=*/box(6));
}, "scroller prefers target aligned in both axes.");
promise_test(async (t) => {
const box7 = box(7), box8 = box(8), box9 = box(9);
const initial_box8_top = box8.offsetTop;
t.add_cleanup(() => {
box8.style.top = `${initial_box8_top}px`;
});
// Snap to box7's row and column.
scroller.scrollTo(box7.offsetLeft, box7.offsetTop);
// Move box 8 below box7 and box9.
box8.style.top = `${box8.offsetTop + 50}px`;
// Snap to box8.
scroller.scrollTop = box8.offsetTop;
// Test that if box7 and box9 are also shifted to align with box8,
// box8 is still treated as the selected snap target despite box7 being
// aligned on both axes.
runLayoutSnapSeletionVerificationTest(t, scroller, [box7, box9],
box8, "y");
}, "scroller follows selected snap target after layout shift, " +
"regardless of common snap area.");
}
</script>
</body>
</html>
|