forked from mathiasbynens/virtual-scroller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrolling.html
84 lines (68 loc) · 2.02 KB
/
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
<html>
<head>
<title>Scrolling</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<style>
body {
font-family: Roboto, Helvetica, sans-serif;
display: flex;
flex-direction: column;
}
#controls {
margin: 10px 0;
}
input {
width: 50px;
}
virtual-scroller {
flex: 1;
height: 100%;
box-sizing: border-box;
border-top: 2px solid #eee;
border-bottom: 2px solid #eee;
}
virtual-scroller>div {
padding: 10px;
box-sizing: border-box;
border-bottom: 1px solid #eee;
}
[layout="horizontal"]>div {
writing-mode: vertical-lr;
}
</style>
</head>
<body>
<div id="controls">
<label>
Scroll to:
<input id="index" type="number" placeholder="index" onchange="scrollToIndex(this.valueAsNumber, position.value)">
<select id="position" onchange="scrollToIndex(index.valueAsNumber, this.value)">
<option value="start">start</option>
<option value="end">end</option>
<option value="center">center</option>
<option value="nearest">nearest</option>
</select>
</label>
<label>
horizontal:
<input type="checkbox" onchange="toggleHorizontal(this.checked)">
</label>
</div>
<virtual-scroller id="scroller"></virtual-scroller>
<script type="module">
import '../virtual-scroller-element.js';
const virtualScroller = document.getElementById('scroller');
virtualScroller.updateElement = (element, contact, index) =>
element.textContent = `${index}) ${contact.longText}`;
fetch('contacts/contacts.json')
.then((resp) => resp.json())
.then((contacts) => virtualScroller.itemSource = contacts);
window.scrollToIndex = (index, position) => {
virtualScroller.scrollToIndex(index, { position });
};
window.toggleHorizontal = (horizontal) => {
virtualScroller.layout = horizontal ? 'horizontal' : 'vertical';
};
</script>
</body>
</html>