-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
125 lines (124 loc) · 9.76 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
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><wc-bell-ring/></title>
<link rel="stylesheet" href="./style/sakura.css" type="text/css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
body{
font-family: 'Figtree', sans-serif;
margin-bottom: 10rem;
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Figtree', sans-serif;
}
</style>
</head>
<body>
<h1><wc-bell-ring/></h1>
<p>A simple ringing bell component.</p>
<p>Demo here: <a href="https://codepen.io/annoyingmouse/pen/gOyQeew">https://codepen.io/annoyingmouse/pen/gOyQeew</a></p>
<h2>Installation</h2>
<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '><</span><span style='color:#800000; font-weight:bold; '>script</span><span style='color:#274796; '> </span><span style='color:#074726; '>type</span><span style='color:#808030; '>=</span><span style='color:#0000e6; '>"module"</span><span style='color:#274796; '></span>
<span style='color:#274796; '> </span><span style='color:#074726; '>src</span><span style='color:#808030; '>=</span><span style='color:#0000e6; '>"https://unpkg.com/@annoyingmouse/wc-bell-ringing/wc-bell-ring.js"</span><span style='color:#a65700; '>></span><span style='color:#a65700; '></</span><span style='color:#800000; font-weight:bold; '>script</span><span style='color:#a65700; '>></span></pre>
<p>Alternatively:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '><</span><span style='color:#800000; font-weight:bold; '>script</span><span style='color:#274796; '> </span><span style='color:#074726; '>type</span><span style='color:#808030; '>=</span><span style='color:#0000e6; '>"module"</span><span style='color:#274796; '></span>
<span style='color:#274796; '> </span><span style='color:#074726; '>src</span><span style='color:#808030; '>=</span><span style='color:#0000e6; '>"https://cdn.skypack.dev/@annoyingmouse/wc-bell-ringing/wc-bell-ring.js"</span><span style='color:#a65700; '>></span><span style='color:#a65700; '></</span><span style='color:#800000; font-weight:bold; '>script</span><span style='color:#a65700; '>></span></pre>
<p>You can use it minified by adding using this instead:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '><</span><span style='color:#800000; font-weight:bold; '>script</span><span style='color:#274796; '> </span><span style='color:#074726; '>type</span><span style='color:#808030; '>=</span><span style='color:#0000e6; '>"module"</span><span style='color:#274796; '></span>
<span style='color:#274796; '> </span><span style='color:#074726; '>src</span><span style='color:#808030; '>=</span><span style='color:#0000e6; '>"[WHATEVER CDN]/@annoyingmouse/wc-bell-ringing/wc-bell-ring.js"</span><span style='color:#a65700; '>></span><span style='color:#a65700; '></</span><span style='color:#800000; font-weight:bold; '>script</span><span style='color:#a65700; '>></span></pre>
<p>Please remember to change <code>[WHATEVER CDN]</code> to your favourite <abbr title="Content Delivery Network">CDN</abbr></p>
<h2>Configuration</h2>
<ul>
<li>Adding a <code>times</code> attribute will dictate the number of times the bell will ring (hint, you can set it to "infinite").</li>
<li>Adding a <code>no-shadow</code> attribute and setting it to <code>true</code> will hide the subtle drop shadow.</li>
<li>Adding a <code>font-size</code> attribute with a valid CSS value will allow you to alter the size of the bell.</li>
<li>Adding a <code>click-to-ring</code> attribute and setting it to <code>true</code> will allow users to click the element to ring it.</li>
<li>Adding a <code>duration</code> attribute with a valid CSS value will alter the speed of the ringing.</li>
</ul>
<p>See the examples:</p>
<h2>Example 01</h2>
<p>Default settings</p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring></wc-bell-ring>
</div>
<hr>
<h2>Example 02</h2>
<p>No drop shadow: <code>no-shadow="true"</code></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring no-shadow="true"></wc-bell-ring>
</div>
<hr>
<h2>Example 03</h2>
<p>Infinite ringing: <code>times="infinite"</code></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring times="infinite"></wc-bell-ring>
</div>
<hr>
<h2>Example 04</h2>
<p>Five rings: <code>times="5"</code></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring times="5"></wc-bell-ring>
</div>
<hr>
<h2>Example 05</h2>
<p>Increase the size: <code>font-size="2em"</code></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring times="5"
font-size="2em"></wc-bell-ring>
</div>
<hr>
<h2>Example 06</h2>
<p>Ring on click: <code>click-to-ring="true"</code></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring click-to-ring="true"
font-size="2em"></wc-bell-ring>
</div>
<hr>
<h2>Example 07</h2>
<p>Ring on click: <code>click-to-ring="true"</code>, with added event listener:</p>
<pre style="color:#000000;background:#ffffff;overflow-x:auto;"><span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>></span> <span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>const</span> bell <span style='color:#808030; '>=</span> document<span style='color:#808030; '>.</span>querySelector<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>#ringing-bell</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>const</span> bellRinging <span style='color:#808030; '>=</span> document<span style='color:#808030; '>.</span>getElementById<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>bell-ringing</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
bell<span style='color:#808030; '>.</span>addEventListener<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>bell-ringing</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>(</span>event<span style='color:#808030; '>)</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>></span> <span style='color:#800080; '>{</span>
console<span style='color:#808030; '>.</span><span style='color:#800000; font-weight:bold; '>log</span><span style='color:#808030; '>(</span>event<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
bellRinging<span style='color:#808030; '>.</span>innerText <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Yes</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
bell<span style='color:#808030; '>.</span>addEventListener<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>bell-stopped</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>(</span>event<span style='color:#808030; '>)</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>></span> <span style='color:#800080; '>{</span>
bellRinging<span style='color:#808030; '>.</span>innerText <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>No</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span><span style='color:#808030; '>)</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span></pre>
<p>Bell ringing <span id="bell-ringing">No</span></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring id="ringing-bell"
click-to-ring="true"
font-size="2em"></wc-bell-ring>
</div>
<hr>
<h2>Example 08</h2>
<p>Ringing speed: <code>duration="5s"</code></p>
<div style="display: flex; align-items: center; justify-content: center;">
<wc-bell-ring duration="5s"
click-to-ring="true"
font-size="2em"></wc-bell-ring>
</div>
<hr>
<script type="module" src="./wc-bell-ring.js"></script>
<script>
(() => {
const bell = document.querySelector("#ringing-bell");
const bellRinging = document.getElementById("bell-ringing");
bell.addEventListener("bell-ringing", (event) => {
console.log(event);
bellRinging.innerText = "Yes";
});
bell.addEventListener("bell-stopped", (event) => {
bellRinging.innerText = "No";
});
})();
</script>
</body>
</html>