-
Notifications
You must be signed in to change notification settings - Fork 7
/
demos.html
113 lines (102 loc) · 3.05 KB
/
demos.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
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Demo</title>
</head>
<script src="./ImgMainColor.js"></script>
<body>
<style>
.item{
float: left;
padding: 50px;
width: 300px;
height: 300px;
}
.item img{
width: 100%;
height: 100%;
}
#file{
width: 100%;
}
.imgfile:after{
content: '';
display: block;
clear: both;
}
</style>
<div class="imgfile">
<input type="file" id="file" />
<div class="item item_file" id="demo"></div>
<div class="item" id="colors"></div>
</div>
<div class="demos"></div>
<script>
function getLocationUrl(file, callback){
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload=function(){
callback(this.result)
}
}
document.getElementById('file').addEventListener('change', function(){
var file = this.files ? this.files[0] : null;
if(!file){return}
getLocationUrl(file, function(src){
document.getElementById('demo').innerHTML = '<img src="'+src+'" />'
new ImgMainColor({
src: src
}, function(color){
document.getElementById('demo').style.backgroundColor=color.hex;
document.getElementById('colors').innerHTML= '<p>HEX:'+color.hex+'</p>' +
'<p>HEXA:'+color.hexa+'</p>' +
'<p>RGB:'+color.rgb+'</p>' +
'<p>RGBA:'+color.rgba+'</p>';
});
})
})
var demos = document.getElementsByClassName('demos')[0];
var html = '';
for(var i=1; i<7; i++){
html += '<div class="item item_'+i+'"> <img src="./demo_'+i+'.png" /> </div>'
}
demos.innerHTML = html;
new ImgMainColor({
src: './demo_1.png'
}, function(color){
document.getElementsByClassName('item_1')[0].style.backgroundColor=color.hex;
});
new ImgMainColor({
src: './demo_2.png',
size: 100,
}, function(color){
document.getElementsByClassName('item_2')[0].style.backgroundColor=color.hex;
});
new ImgMainColor({
src: './demo_3.png',
exclude: ['#e5e2e2', '#20211e'],
}, function(color){
document.getElementsByClassName('item_3')[0].style.backgroundColor=color.rgb;
});
new ImgMainColor({
src: './demo_4.png',
exclude: ['#fff'],
}, function(color){
document.getElementsByClassName('item_4')[0].style.backgroundColor=color.rgb;
});
new ImgMainColor({
src: './demo_5.png',
exclude: ['rgba(189, 196, 192, 0.498039)'],
}, function(color){
document.getElementsByClassName('item_5')[0].style.backgroundColor=color.rgba;
});
new ImgMainColor({
src: './demo_6.png',
level: 16,
}, function(color){
document.getElementsByClassName('item_6')[0].style.backgroundColor=color.rgba;
});
</script>
</body>
</html>