-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.html
141 lines (116 loc) · 3.88 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<title>nearest-color demo</title>
<style type="text/css">
body > div {
width: 960px;
margin: auto;
}
h1 {
font-family: sans-serif;
border-bottom: 1px solid black;
}
p {
font-size: 150%;
}
h3 {
margin-bottom: 0;
}
.palette span {
display: inline-block;
height: 30px;
width: 30px;
margin-right: 10px;
}
.sample {
height: 300px;
}
.actual,
.nearest {
position: relative;
display: inline-block;
width: 50%;
height: 100%;
}
.actual:before {
position: absolute;
display: block;
content: "Actual";
top: calc(50% - 10px);
left: 0;
right: 0;
line-height: 20px;
text-align: center;
}
.nearest:before {
position: absolute;
display: block;
content: "Nearest";
top: calc(50% - 10px);
left: 0;
right: 0;
line-height: 20px;
text-align: center;
}
</style>
<script src="nearestColor.js"></script>
</head>
<body>
<div>
<h1>nearest-color</h1>
<p>
Choose a color using the picker. The color you selected will be
displayed on the left, and the nearest color from the list of
defaults will appear on the right.
</p>
<form>
<h3>Select a color</h3>
<input type="color" name="color" />
</form>
<div class="palette" id="default-palette">
<h3>Default colors</h3>
</div>
<div class="sample" id="default-sample">
<div class="actual"></div><div class="nearest"></div>
</div>
<div class="palette" id="alternate-palette">
<h3>Alternate palette</h3>
</div>
<div class="sample" id="alternate-sample">
<div class="actual"></div><div class="nearest"></div>
</div>
<!-- "Fork me on GitHub" ribbon -->
<a href="https://github.com/dtao/nearest-color"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github-camo.global.ssl.fastly.net/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
</div>
<script>
var colorPicker = document.querySelector('input[name="color"]');
function prepareSection(label, colors) {
var palette = document.getElementById(label + '-palette'),
sample = document.getElementById(label + '-sample'),
actual = sample.querySelector('.actual'),
nearest = sample.querySelector('.nearest'),
getColor = nearestColor.from(colors);
colorPicker.addEventListener('change', function() {
var value = colorPicker.value;
actual.style.backgroundColor = value;
nearest.style.backgroundColor = getColor(value);
});
colors.forEach(function(color) {
var span = document.createElement('SPAN');
span.style.backgroundColor = color.source || color;
palette.appendChild(span);
});
}
prepareSection('default', nearestColor.DEFAULT_COLORS);
prepareSection('alternate', [
'#7EB5D6',
'#2A75A9',
'#274257',
'#DFC184',
'#8F6048',
'#644436'
]);
</script>
</body>
</html>