-
Notifications
You must be signed in to change notification settings - Fork 0
/
hexcolorcode.html
96 lines (86 loc) · 3.54 KB
/
hexcolorcode.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
<!DOCTYPE html>
<html lang="ja">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RGBシミュレーター</title>
<!-- ogp -->
<meta property="og:url" content="https://progedu.github.io/rgb-simulator" />
<meta property="og:title" content="RGBシミュレーター" />
<meta property="og:description" content="RGBの値を調節して色の変化を確認できます。" />
<meta property="og:site_name" content="progedu.github.io/rgb-simulator" />
<meta property="og:image" content="https://progedu.github.io/rgb-simulator/ogp.png" />
<meta property="og:type" content="website" />
<!-- ogp Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous" />
<style>
.color-legend-wrapper {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
padding: 40px;
display: inline-block;
}
.color-legend {
background: white;
padding: 10px;
font-weight: bold;
}
.hash {
font-size: 2rem;
margin-right: .4rem;
}
input[type="text"] {
border: 4px solid #ddd;
padding: 5px;
width: 9rem;
font-size: 2rem;
}
input[type="text"]::placeholder {
color: #ccc;
}
span {
display: inline-block;
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script>
function getValue() {
try {
let a = document.getElementById("hexinput").value;
let regex = new RegExp(/([a-fA-F0-9]{3}|[a-fA-F0-9]{6})/);
if (regex.test(a)) {
document.getElementById('color-legend-wrapper').style.backgroundColor = '#' + a;
} else {
document.getElementById('color-legend-wrapper').style.backgroundColor = 'transparent';
}
} catch (e) {
document.getElementById('color-legend-wrapper').style.backgroundColor = 'transparent';
}
var $hexcode = document.getElementById("hexinput").value;
document.getElementById("hexoutput").innerHTML = $hexcode;
}
function del() {
document.getElementById("hexinput").value = '';
document.getElementById('color-legend-wrapper').style.backgroundColor = 'transparent';
document.getElementById("hexinput").focus();
}
</script>
<div id="app" class="container mt-5">
<h2>16進数で入力してみよう</h2>
<br>
<div>
<span class="hash">#</span> <input type="text" id="hexinput" onkeyup="getValue();">
<input type="button" id="btn1" value="クリア" onclick="del();">
<br>
<br>
<div id="color-legend-wrapper"> <span class="color-legend">色の見本:#<span id="hexoutput"></span></span>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</body>
</html>