-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhue.html
162 lines (150 loc) · 4.7 KB
/
hue.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html>
<head>
<title>rgbaster.js</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<script type="text/javascript" src='rgbaster.min.js'></script>
<script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.16.1/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css">
<link id="css" data-theme="bootstrap" rel="stylesheet" href="https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
<style type="text/css">
* {
transition: all 250ms ease-out;
}
body {
text-align: center;
overflow: auto;
}
#image {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
text-align: center;
border: 10px solid #eee;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2);
width: auto;
max-width: 90%;
height: auto;
display: inline-block;
margin: auto;
border-radius: .25rem;
}
#palette {
padding: 5px;
background: #333;
position: fixed;
top: 10px;
left: 10px;
z-index: 2;
border-radius: .25rem;
display: flex;
width: 62px;
flex-wrap: wrap;
}
#palette.hidden {
display: none;
}
#palette .color {
width: 20px;
height: 20px;
margin: 3px;
}
.link {
position: fixed;
z-index: 1;
width: calc(100vw - 2 * 85px);
top: 0;
left: 0;
right: 0;
padding-top: 1em;
margin: auto;
text-align: center;
}
.btn-outline-secondary {
background-color:var(--background-color);
}
#link {
background: #fff6;
}
[hidden] {
display: none !important;
}
</style>
</head>
<body onload='onload()'>
<div id='palette' class="hidden"></div>
<div class="input-group mb-3 link">
<input type="text" class="form-control" id="link" />
<button class="btn btn-outline-secondary" type="button" onclick="go()">确定</button>
<button class="btn btn-outline-secondary" type="button" onclick="document.getElementById('browse').click();">浏览</button>
</div>
<input type="file" id="browse" accept="image/*" hidden>
<img src="img.jpg" id='image'>
</body>
<script>
function onload() {
var img = document.getElementById('image');
var colors = RGBaster.colors(img, {
paletteSize: 30,
success: function(colors) {
img.style.borderColor = colors.palette[0];
var makeDivWithClassAndBGColor = function(klass, color) {
var div = document.createElement("div");
div.className = klass;
div.style.backgroundColor = color;
return div;
};
console.log("-----------------------------------------------");
console.log("rgbaster.js");
console.log("-----------------------------------------------");
console.log("Dominant color:", colors.dominant);
console.log("Secondary color:", colors.secondary);
console.log("Palette length:", colors.palette.length);
console.log("-----------------------------------------------");
var palette = document.getElementById('palette');
palette.classList.add("hidden");
palette.innerHTML = "";
palette.appendChild(makeDivWithClassAndBGColor('color', colors.dominant));
colors.palette.forEach(function(color) {
palette.appendChild(makeDivWithClassAndBGColor('color', color));
});
palette.classList.remove("hidden");
resize();
}
});
}
window.onresize = resize;
function resize(){
var height=document.documentElement.clientHeight, width=document.documentElement.clientWidth;
var img=document.getElementById("image");
var picHeight=img.height, picWidth=img.width;
var margin = 50;
if(picHeight*width/picWidth<=height) img.style.transform = `scale(${(width-margin)/picWidth})`;
else img.style.transform = `scale(${(height-margin)/picHeight})`;
}
function go(){
var link=document.getElementById("link").value;
if (link=="") link="img.jpg";
document.getElementById("image").src=link;
onload();
}
document.onkeydown = function(e) {
if (window.event.keyCode == 13) {
if($("#link").is(":focus")) document.querySelector("[onclick='go()']").click();
}
}
document.getElementById("browse").addEventListener("change", function () {
if (this.files.length) {
document.getElementById("link").value = URL.createObjectURL(this.files[0]);
go();
}
});
</script>
<script src="/basis/NightTime.js"></script>
</html>