forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid-item-width-changes-scrolling.html
93 lines (80 loc) · 2.01 KB
/
grid-item-width-changes-scrolling.html
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
<!doctype HTML>
<!--
This test creates a grid with 10,000 non-trivial items below the viewport.
It sets content-visibility: hidden on the container and adjusts one item width continuously.
On a certain iteration it sets spacer height to zero, thus causing the grid
to render in the viewport.
-->
<style>
#container {
content-visibility: hidden;
width: 500px;
height: 500px;
display: grid;
border: 1px solid black;
background: lightblue;
}
.item {
background: blue;
margin: 1px;
width: 10%;
height: 10%;
}
#spacer {
height: 200vh;
}
</style>
<template id="item_template">
<div class="item">
<div id="target" style="position: relative; width: 80%;">
relpos
<div style="position: absolute; top: 1px; left: 1%">
abspos
</div>
</div>
<div style="position: absolute; top: 1px; left: 1%">
abspos
</div>
lorem ipsum dolor sit amet
</div>
</template>
<div id=spacer></div>
<div id=container></div>
<script src="../resources/runner.js"></script>
<script>
function construct(n) {
const specimen = document.importNode(document.getElementById("item_template").content, true).firstElementChild;
const container = document.getElementById("container");
for (let i = 0; i < n; ++i) {
const clone = specimen.cloneNode(true);
container.appendChild(clone);
}
}
construct(10000);
let widths = ["90%", "95%"];
let width_index = 0;
function changeStyle() {
document.getElementById("target").style.width = widths[width_index];
width_index = 1 - width_index;
}
let testDone = false;
let startTime;
let currentIteration = 0;
function runTest() {
currentIteration++;
if (startTime)
PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime);
if (testDone)
return;
startTime = PerfTestRunner.now();
changeStyle();
if (currentIteration == 3)
spacer.style.height = "0px";
requestAnimationFrame(runTest);
}
PerfTestRunner.prepareToMeasureValuesAsync({
unit: 'ms',
done: () => { testDone = true; container.innerHTML = ""; }
});
requestAnimationFrame(runTest);
</script>