-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
186 lines (175 loc) · 4.9 KB
/
index.html
File metadata and controls
186 lines (175 loc) · 4.9 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title><layflags-rolling-number> - Demo</title>
<style>
* {
box-sizing: border-box;
}
html {
min-height: 100vh;
background: linear-gradient(45deg, lightgoldenrodyellow, lightcyan);
}
body {
color: black;
font-family: monospace;
margin: 0;
padding: 0;
}
main {
max-width: 600px;
margin: 0 auto;
padding: 2em 1em;
}
hr {
border: none;
border-top: 1px solid rgba(0, 0, 0, 0.3);
margin: 1.5rem 0;
}
h1 {
font-size: 200%;
margin: 1.4rem 0;
}
h1 span {
font-size: 60%;
color: blue;
text-transform: uppercase;
}
form {
display: flex;
width: 100%;
font-size: 200%;
border-radius: 0.4rem;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
}
form input,
form button {
font-family: inherit;
font-size: inherit;
border: none;
padding: 0.2em 0.6em;
border-radius: 0.4rem;
border-left: 0.05em solid white;
display: block;
}
form input {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
background-color: white;
color: black;
flex-grow: 1;
width: 100%;
}
form button {
background-color: blue;
color: white;
padding-right: 0.75em;
}
form button[type="button"] {
border-radius: 0;
background-color: green;
}
form button[type="submit"] {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
form button:hover {
background-color: darkblue;
}
form button:active {
color: lightblue;
}
textarea {
border: none;
padding: 1em;
border-radius: 0.4rem;
width: 100%;
max-width: 600px;
font: inherit;
}
.output {
font-size: 500%;
margin: 1.4rem 0 0.4rem 0;
color: green;
background-color: lightgreen;
display: inline-block;
padding: 0 0.2em;
border: 1px solid rgb(0, 180, 0);
border-radius: 0.4rem;
}
</style>
<script type="module" src="./rolling-number.js"></script>
</head>
<body>
<main>
<a
href="https://github.com/layflags/rolling-number"
title="Show project on GitHub"
style="float: right"
><img src="./github.svg" width="32" height="32" alt="GitHub Logo"
/></a>
<h1><layflags-rolling-number><br /><span>Demo</span></h1>
<p>
<layflags-rolling-number> is an easy-to-use inline Web Component
that shows a nice rolling digit animation and automatically adapts to
the surrounding font style (family, color, size, etc.).
</p>
<h2>Playground</h2>
<form id="form">
<input type="number" name="number" value="123" size="6" />
<button type="button" id="randomize">rnd</button>
<button type="submit">set</button>
</form>
<div class="output">
<layflags-rolling-number class="rolling" style="--roll-duration: 750ms"
>123</layflags-rolling-number
>°C
</div>
<p style="font-family: serif; font-style: italic">
It's around
<layflags-rolling-number class="rolling" style="--roll-duration: 1500ms"
>123</layflags-rolling-number
>°C at the moment!
</p>
<p></p>
<h2>Usage</h2>
<p>
<textarea readonly rows="12">
<script type="module" src="https://unpkg.com/@layflags/rolling-number@1.0.0/rolling-number.js"></script>
<!-- value by fallback -->
<layflags-rolling-number>123</layflags-rolling-number>
<!-- value w/o fallback -->
<layflags-rolling-number value="123"></layflags-rolling-number>
<!-- customize roll duration -->
<layflags-rolling-number style="--roll-duration:750ms">123</layflags-rolling-number>
</textarea
>
</p>
<hr />
<p>
<small
>2021 by
<a href="https://www.layfla.gs" target="_blank">layflags</a></small
>
</p>
</main>
<script>
document.getElementById("form").addEventListener("submit", (evt) => {
const { value } = evt.target.number;
document.querySelectorAll(".rolling").forEach((node) => {
node.value = value;
});
evt.preventDefault();
});
document.getElementById("randomize").addEventListener("click", (evt) => {
const randomValue = Math.round(Math.random() * 998) - 499;
evt.target.form.number.value = randomValue;
document.querySelectorAll(".rolling").forEach((node) => {
node.value = randomValue;
});
});
</script>
</body>
</html>