-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
114 lines (109 loc) · 3.25 KB
/
index.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!doctype>
<html>
<head>
<style>
body {
margin: 0;
font-family: sans-serif;
display: flex;
}
#container {
width: 80vw;
height: 100vh;
flex-grow: 1;
scroll-behavior: smooth;
-webkit-touch-overflow: scroll;
-webkit-overflow-scrolling: touch;
}
#table {
position: relative;
}
#table > .row {
display: block;
overflow: hidden;
position: absolute;
width: 100%;
}
#table > .row > .cell {
display: block;
line-height: 50px;
box-sizing: border-box;
overflow: hidden;
text-align: center;
position: absolute;
}
#table > .row > .cell.search-match {
background: yellow !important;
}
#debug {
top: 0;
right: 0;
width: 250px;
height: 100vh;
background: #eee;
padding: 20px;
margin: 0;
box-sizing: border-box;
}
#debug > dt {
display: inline-block;
width: 66.66%;
margin: 0 0 10px 0;
}
#debug > dd {
text-align: right;
display: inline-block;
width: 33.33%;
margin: 0 0 10px 0;
}
</style>
</head>
<body>
<div id="container">
<div id="table"></div>
</div>
</body>
<script src="virtual-scroll.js"></script>
<script>
let cell = document.createElement('div')
cell.setAttribute('class', 'cell')
cell.contentEditable = true
let ny = 10e3, nx = 100
let data = []
for (let i = 0; i < ny; i++) {
let row = []
for (let j = 0; j < nx; j++) {
let number = Math.round(Math.random() * 100)
row.push(number)
}
data.push(row)
}
let dataProxy = new Proxy(data, {
deleteProperty: (target, property) => {
delete target[property]
return true
},
set: (target, property, value, receiver) => {
target[property] = value
if (/^\d+$/.test(property)) {
console.log('updated data', property, value)
}
return true
}
})
var table = new VirtualScroll({
element: document.getElementById('table'),
data: dataProxy,
cellHeight: 50,
cellWidth: 200,
debug: true,
cell,
update: (cell, value, rowNumber, columnNumber) => {
// cell.innerHTML = String(value || '')
cell.innerHTML = `${rowNumber}:${columnNumber}`
let g = Math.round(value / 100 * 255)
cell.style.background = `rgba(255, ${g}, 255, 1)`
}
})
</script>
</html>