-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.html
66 lines (56 loc) · 1.63 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSSX</title>
</head>
<body>
<h1>Hello <small>CSSX</small> world!</h1>
<button data-color="#F00">red</button>
<button data-color="#0F0">green</button>
<button data-color="#00F">blue</button>
<pre></pre>
<br /><br />
<button id="colorize">click me</button>
<script src="../../packages/cssx/lib/cssx.js"></script>
<script>
cssx.minify(false);
var h1Color = '#000';
var randomColor = '#000';
var updateStyles = function () {
var stylesheet = cssx('my-styles');
var body = stylesheet.add('body');
var h1 = body.descendant({'h1': { 'color': h1Color }});
h1.descendant({ 'small': { 'font-size': '0.3em' }});
stylesheet.add({ '#colorize': { color: randomColor }});
showGeneratedCSS();
};
// buttons
[].slice.call(document.querySelectorAll('button[data-color]')).forEach(function (btn) {
btn.addEventListener('click', function () {
h1Color = btn.getAttribute('data-color');
updateStyles();
});
});
// random
document.querySelector('#colorize').addEventListener('click', function () {
randomColor = getRandomColor();
updateStyles();
});
// helpers
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};
function showGeneratedCSS(css) {
document.querySelector('pre').innerHTML = cssx.getCSS();
};
// first run
updateStyles();
</script>
</body>
</html>