Custom Color support

master
Joshua Sigona 5 years ago
parent 8d1614dcb0
commit 7d325ddccc
  1. 43
      canvas.js
  2. 8
      index.html
  3. 14
      style.css
  4. BIN
      transparent.png

@ -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="canvas">
<div class="container">
<div class="canvas">
</div>
</div>
<div class="toolbar">
</div>
</body>
</html>

@ -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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Loading…
Cancel
Save