Skip to content

Commit e435fc2

Browse files
hiikezoemoz-wptsync-bot
authored andcommitted
Do not clobber restoring the scroll position on re-snap.
Differential Revision: https://phabricator.services.mozilla.com/D239677 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1950560 gecko-commit: 6f402158997013a24abbdff497db52c4e82630dd gecko-reviewers: botond
1 parent 451b62d commit e435fc2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap/#re-snap" />
3+
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1948861">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<style>
7+
#scroller {
8+
scroll-snap-type: y mandatory;
9+
width: 500px;
10+
height: 200px;
11+
overflow-y: scroll;
12+
overflow-x: hidden;
13+
scrollbar-width: none;
14+
}
15+
.child {
16+
scroll-snap-align: start;
17+
width: 500px;
18+
height: 100%;
19+
}
20+
video {
21+
height: 100%;
22+
}
23+
</style>
24+
<div id="container">
25+
<div id="scroller">
26+
<div class="child">
27+
<video src="dummy.webm" controls autoplay>
28+
</div>
29+
<div class="child">
30+
<video src="dummy.webm" controls autoplay>
31+
</div>
32+
<div class="child">
33+
<video src="dummy.webm" controls autoplay>
34+
</div>
35+
</div>
36+
</div>
37+
<script>
38+
promise_test(async () => {
39+
assert_equals(scroller.scrollTop, 0);
40+
41+
const scrollendPromise = new Promise(resolve => {
42+
scroller.addEventListener("scrollend", resolve);
43+
});
44+
// Try to scroll downward, it will snap to the second green box.
45+
scroller.scrollBy({ top: 100, behavior: "smooth" });
46+
await scrollendPromise;
47+
48+
// Change the parent position style so that the scroll container will
49+
// be reconstructed.
50+
container.style.position = "fixed";
51+
52+
assert_equals(scroller.scrollTop, 200, "Should stay at the last snap point");
53+
}, "Stay at the last snap point even after reconstrucing the scroll container");
54+
</script>

0 commit comments

Comments
 (0)