File: position-sticky-overflow-hidden.html

package info (click to toggle)
firefox-esr 78.15.0esr-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,301,296 kB
  • sloc: cpp: 5,665,905; javascript: 4,798,386; ansic: 2,878,233; python: 977,004; asm: 270,347; xml: 181,456; java: 111,756; sh: 72,926; makefile: 21,819; perl: 13,380; cs: 4,725; yacc: 4,565; objc: 3,026; pascal: 1,787; lex: 1,720; ada: 1,681; exp: 505; php: 436; lisp: 260; awk: 152; ruby: 103; csh: 80; sed: 53; sql: 45
file content (86 lines) | stat: -rw-r--r-- 3,001 bytes parent folder | download | duplicates (6)
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
<!DOCTYPE html>
<title>position:sticky elements should respect an overflow:hidden ancestor</title>
<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
<meta name="assert" content="This test checks that position:sticky elements adhere to an overflow:hidden ancestor" />

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="resources/sticky-util.js"></script>

<body></body>

<script>
test(() => {
  const outer_scroller = document.createElement('div');
  outer_scroller.style.width = '100px';
  outer_scroller.style.height = '100px';
  outer_scroller.style.overflow = 'scroll';

  const inner_scroller = document.createElement('div');
  inner_scroller.style.width = '80%';
  inner_scroller.style.height = '200px';
  inner_scroller.style.overflow = 'hidden';

  const sticky = document.createElement('div');
  sticky.style.width = '20px';
  sticky.style.height = '20px';
  sticky.style.position = 'sticky';
  sticky.style.top = '0';
  sticky.style.background = 'red';

  const spacer = document.createElement('div');
  spacer.style.height = '500px';

  inner_scroller.appendChild(sticky);
  inner_scroller.appendChild(spacer);
  outer_scroller.appendChild(inner_scroller);
  document.body.appendChild(outer_scroller);

  outer_scroller.scrollTop = 50;

  // The sticky should attach to the inner scroller, and so should not stick.
  assert_equals(sticky.offsetTop, inner_scroller.offsetTop);
}, 'A sticky element should attach to an overflow:hidden ancestor');

// This tests a specific bug in Firefox where the sticky element incorrectly
// started sticking when inside a table. See https://bugzilla.mozilla.org/show_bug.cgi?id=1488810
test(() => {
  const outer_scroller = document.createElement('div');
  outer_scroller.style.width = '100px';
  outer_scroller.style.height = '100px';
  outer_scroller.style.overflow = 'scroll';

  const table = document.createElement('div');
  table.style.display = 'table';

  const tr = document.createElement('div');
  tr.style.display = 'table-row';

  const inner_scroller = document.createElement('div');
  inner_scroller.style.display = 'table-cell';
  inner_scroller.style.overflow = 'hidden';

  const sticky = document.createElement('div');
  sticky.style.width = '20px';
  sticky.style.height = '20px';
  sticky.style.position = 'sticky';
  sticky.style.top = '0';
  sticky.style.background = 'red';

  const spacer = document.createElement('div');
  spacer.style.height = '500px';

  inner_scroller.appendChild(sticky);
  inner_scroller.appendChild(spacer);
  tr.append(inner_scroller);
  table.appendChild(tr);
  outer_scroller.appendChild(table);
  document.body.appendChild(outer_scroller);

  outer_scroller.scrollTop = 50;

  // The sticky should attach to the inner scroller, and so should not stick.
  assert_equals(sticky.offsetTop, inner_scroller.offsetTop);
}, 'A sticky element should attach to an overflow:hidden ancestor inside a table');
</script>