forked from liriliri/licia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomColor.demo.html
40 lines (35 loc) · 1.15 KB
/
randomColor.demo.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
<require>$ randomColor evalCss</require>
<style>
.color {
display: inline-block;
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 10px;
}
</style>
<template id="bodyTpl">
<div class="colors"></div>
<button id="generate">Generate</button>
<button id="generate-hue">Generate Hue 100</button>
<button id="generate-lightness">Generate Lightness 0.6</button>
<button id="generate-seed">Generate Seed 252</button>
</template>
<script>
evalCss(style);
$('body').html(bodyTpl);
function generate(options = {}) {
const count = 100;
options.count = count;
const colors = randomColor(options);
let html = '';
for (let i = 0; i < count; i++) {
html += `<span class="color" style="background:${colors[i]}"></span>`;
}
$('.colors').html(html);
}
$('#generate').on('click', () => generate());
$('#generate-hue').on('click', () => generate({ hue: 100 }));
$('#generate-lightness').on('click', () => generate({ lightness: 0.6 }));
$('#generate-seed').on('click', () => generate({ seed: 252 }));
</script>