Custom Color support
This commit is contained in:
parent
8d1614dcb0
commit
7d325ddccc
43
canvas.js
43
canvas.js
@ -5,6 +5,7 @@ var unselectedColorBorder = "2px black solid";
|
||||
|
||||
document.addEventListener("DOMContentLoaded",()=>{
|
||||
var canvas = document.getElementsByClassName("canvas")[0];
|
||||
var toolbar = document.getElementsByClassName("toolbar")[0];
|
||||
var MouseListener = (e)=>{
|
||||
e.preventDefault();
|
||||
if (mouseState>=0) {
|
||||
@ -40,6 +41,7 @@ document.addEventListener("DOMContentLoaded",()=>{
|
||||
var row = document.createElement("tr");
|
||||
for (var j=0;j<columns;j++) {
|
||||
var col = document.createElement("th");
|
||||
col.style.background="white";
|
||||
row.appendChild(col);
|
||||
}
|
||||
table.appendChild(row);
|
||||
@ -71,11 +73,48 @@ document.addEventListener("DOMContentLoaded",()=>{
|
||||
e.target.style.border=selectedColorBorder;
|
||||
selectedColor = e.target.style.background;
|
||||
})
|
||||
canvas.appendChild(dot);
|
||||
toolbar.appendChild(dot);
|
||||
}
|
||||
var customColorContainer = document.createElement("div");
|
||||
customColorContainer.classList.add("toolbar")
|
||||
var customColorToolbar=false;
|
||||
var dot = document.createElement("img")
|
||||
dot.classList.add("dot")
|
||||
dot.src="colorwheel.png"
|
||||
customColorContainer.append(dot);
|
||||
toolbar.appendChild(customColorContainer);
|
||||
customColorContainer.addEventListener("click",(e)=>{
|
||||
if (customColorToolbar) {
|
||||
var otherDots = document.getElementsByClassName("dot");
|
||||
for (var i=0;i<otherDots.length;i++) {
|
||||
var dot2 = otherDots[i];
|
||||
dot2.style.border=unselectedColorBorder;
|
||||
}
|
||||
dot.style.border=selectedColorBorder;
|
||||
} else {
|
||||
var customColorInput = document.createElement("input");
|
||||
customColorInput.type="color"
|
||||
customColorInput.value="#222222"
|
||||
customColorInput.classList.add("customColor")
|
||||
customColorContainer.appendChild(customColorInput);
|
||||
customColorInput.addEventListener("change",(e)=>{
|
||||
dot.style.background=e.target.value
|
||||
selectedColor=e.target.value
|
||||
})
|
||||
dot.src="transparent.png";
|
||||
dot.style.background=customColorInput.value;
|
||||
customColorToolbar=true;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
generateTable(20,20);
|
||||
generateTable(30,30);
|
||||
canvas.appendChild(document.createElement("br"))
|
||||
generateColors(false);
|
||||
|
||||
document.addEventListener("scroll",()=>{
|
||||
toolbar.style.position="absolute";
|
||||
toolbar.style.left=window.scrollX+"px";
|
||||
toolbar.style.bottom=-window.scrollY+"px";
|
||||
})
|
||||
})
|
@ -8,8 +8,12 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="canvas">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
14
style.css
14
style.css
@ -9,6 +9,20 @@ th{
|
||||
width:16px;
|
||||
height:16px;
|
||||
}
|
||||
.container{
|
||||
text-align: center;
|
||||
}
|
||||
.canvas{
|
||||
display:inline-block;
|
||||
background-color: #EEEEFF;
|
||||
border-radius: 10%;
|
||||
padding: 48px;
|
||||
}
|
||||
.customColor{
|
||||
vertical-align: middle;
|
||||
position:relative;
|
||||
top:-8px;
|
||||
}
|
||||
.dot{
|
||||
height: 25px;
|
||||
width: 25px;
|
||||
|
BIN
transparent.png
Normal file
BIN
transparent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
Loading…
x
Reference in New Issue
Block a user