Skip to content

Commit 530c390

Browse files
committed
updaet demo
1 parent 3f68a8d commit 530c390

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

demo/index.html

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,47 @@
1111

1212
<h1>Tiny-events.js</h1>
1313
<p>
14-
TinyEvents is a tiny, framework-agnostic, event utility library for
15-
modern browsers(IE 11+). Supports jQuery like syntax. Just 1 kb
16-
gzipped.
14+
TinyEvents is a tiny event utility library for modern browsers(IE
15+
11+). Supports jQuery like syntax. Just 1 kb gzipped.
1716
</p>
17+
<div class="color-code-wrap">
18+
Color code <span id="color-code">#FFF</span>
19+
</div>
1820
<script>
19-
const getRandomColor = () =>
20-
'#' + Math.floor(Math.random() * 16777215).toString(16);
21+
tinyEvents('.change-bg').on(
22+
'click.sample mouseover.sample',
23+
function () {
24+
const color = getRandomColor();
25+
document.body.style.backgroundColor = color;
26+
triggerColorChange(color);
27+
}
28+
);
2129

22-
tinyEvents('.change-bg').on('click.sample mouseover.sample', () => {
23-
document.body.style.backgroundColor = getRandomColor();
30+
tinyEvents('.change-color').on('click.sample', function () {
31+
const color = getRandomColor();
32+
document.body.style.color = color;
33+
triggerColorChange(color);
2434
});
2535

26-
tinyEvents('.change-color').on('click.sample', () => {
27-
document.body.style.color = getRandomColor();
36+
tinyEvents('.remove-btn').on('click', function () {
37+
tinyEvents('.change-bg, .change-color').off('.sample');
2838
});
2939

30-
tinyEvents('.remove-btn').on('click', () => {
31-
tinyEvents('.change-bg, .change-color').off('.sample');
40+
tinyEvents('#color-code').on('color-change', function (event) {
41+
const color = event.detail.color;
42+
document.getElementById('color-code').innerHTML = color;
3243
});
44+
45+
function getRandomColor() {
46+
return '#' + Math.floor(Math.random() * 16777215).toString(16);
47+
}
48+
49+
function triggerColorChange(color) {
50+
// Custom events demo
51+
tinyEvents('#color-code').trigger('color-change', {
52+
color: color
53+
});
54+
}
3355
</script>
3456
</body>
3557
</html>

0 commit comments

Comments
 (0)