-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
68 lines (58 loc) · 1.69 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="icon" type="image/png" href="https://reach.tech/favicon.png" />
<title>Reach observeRect</title>
</head>
<body style="
background: #eee;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
">
<pre
id="log"
style="
background: #333;
color: white;
padding: 20px;
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', 'Droid Sans Mono', 'Source Code Pro', monospace;
"
>
You need to run this from a file server.
From the root of this project run
$ serve
then open up <a style="color: white" href="http://localhost:5000/example.html">http://localhost:5000/example.html</a>.
</pre>
<button id="toggle">unobserve</button>
<br/><br/>
<textarea>Resize this</textarea>
<span
id="demo"
contenteditable
style="
display: inline-block;
padding: 10px;
border: solid 1px;
background: white;
"
>I am being measured, you can edit me!</span>
</body>
<script type="module">
import observeRect from './dist/observe-rect.esm.js'
let observer = observeRect(demo, (rect) => {
log.textContent = JSON.stringify(rect, null, 2)
})
observer.observe()
let observing = true
toggle.addEventListener('click', () => {
if (observing) {
observer.unobserve()
toggle.textContent = 'observe'
} else {
observer.observe()
toggle.textContent = 'unobserve'
}
observing = !observing
})
</script>
</html>