-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule.html
49 lines (44 loc) · 1001 Bytes
/
module.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
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1">
<title>Computed Variables Demo</title>
<style>
:root {
--innerWidth: 'innerWidth';
--innerHeight: 'innerHeight';
--cursorX: 'clientX';
--cursorY: 'clientY';
}
html {
cursor: none;
background: #222;
}
div {
width: 50px;
height: 50px;
position: fixed;
border-radius: 100%;
border-top-left-radius: 0;
top: calc(var(--cursorY) * 1px);
left: calc(var(--cursorX) * 1px);
background: hsl(var(--cursorX), 75%, 50%);
}
</style>
<div></div>
<script type=module>
import computedVariables from '../index.es.js'
// innerWidth and innerHeight
computedVariables(
'--inner',
value => window[value],
window,
['load', 'resize']
)
// cursor X and Y coordinates
computedVariables(
'--cursor',
(value, event) => event[value] || event.touches[0][value],
window,
['mousemove', 'touchmove']
)
</script>