Skip to content

added copy button issue #3 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added copy-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions css/darkaqua.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ div.misc1 {
transition: 0.4s;
}

.button3 {
background-color: transparent;
border: none;
cursor: pointer;
transform: scale(.7);
transition: 0.4s;
}
.button3 img {
height: 3em;
filter: invert(86%) sepia(42%) saturate(3730%) hue-rotate(122deg) brightness(97%) contrast(103%);
}
.button1 {}
.button2 {}

.button1:hover {
background-color: #a0ffff;
transform: scale(1.1);
Expand All @@ -159,6 +173,50 @@ div.misc1 {
transform: scale(1.1);
color: #001717;
}
.button3 img:hover,
.button3 img:focus {
filter: invert(94%) sepia(84%) saturate(2523%) hue-rotate(163deg) brightness(106%) contrast(105%);
transform: scale(1.1);
}
/* copy code tooltip */
#copyTooltip {
position: relative;
display: inline-block;
bottom: 100%;
left: 10%;
color: #00f5f5;
cursor: auto;
}
/* animation to remove tooltip */
.slide-out-bck-center {
-webkit-animation: slide-out-bck-center 3s cubic-bezier(0.550, 0.085, 0.680, 0.530) 1s both;
animation: slide-out-bck-center 3s cubic-bezier(0.550, 0.085, 0.680, 0.530) 1s both;
}
@-webkit-keyframes slide-out-bck-center {
0% {
-webkit-transform: translateZ(0);
transform: translateZ(0);
opacity: 1;
}
100% {
-webkit-transform: translateZ(-1100px);
transform: translateZ(-1100px);
opacity: 0;
}
}
@keyframes slide-out-bck-center {
0% {
-webkit-transform: translateZ(0);
transform: translateZ(0);
opacity: 1;
}
100% {
-webkit-transform: translateZ(-1100px);
transform: translateZ(-1100px);
opacity: 0;
}
}

.box1 {
margin-top: 30px;
border: 1px solid #00f5f5;
Expand All @@ -174,6 +232,12 @@ div.misc1 {
border-radius: 5px;
background: #001717;
}
.hex-info {
display: flex;
justify-content: center;
align-items: center;
height: 3em;
}
label {
text-transform: uppercase;
margin: 20px 0px;
Expand Down
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Hex© Color Code</title>
<link rel="icon" href="./logo.jpg" type="image/jpg">
<script src="./js/script.js"></script>
<!-- <script src="./js/script.js"></script> -->
<link rel="stylesheet" href="./css/darkaqua.css">
<!-- Add social icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
Expand Down Expand Up @@ -35,7 +35,10 @@
<input type="color" id="color-box" class="input"></input>
<button onclick="check1()" class="b button1" id="but1">Color to Hex Code</button>
<button onclick="check2()" class="b button2" id="but2">Hex Code to Color</button>
<input value="Enter #Hex Code" class="input margin20 b textbox" id="value-box"></input>
<div class="hex-info">
<input placeholder="Enter #Hex Code" class="input margin20 b textbox" id="value-box"></input>
<button class="b button3" title="Copy to clipboard"><img src="copy-icon.png" alt="" id="copyButton"><span class="copyText" id="copyTooltip"></span></button>
</div>
<label class="label margin20">
<label class="a">Enter<text class="t"><b>#hex</b></text>Code</label>
</label>
Expand All @@ -60,6 +63,7 @@
@github</text><br /></a>
<text2 class="u" style="font-size:12px; margin:5px;">-owned by Yashvardhan Baid</text2>
</div>
<script src="./js/script.js"></script>
</body>

</html>
47 changes: 33 additions & 14 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
(function(window, document) {})(window, document);
(function (window, document) {})(window, document);

function check1() {
var x = document.getElementsByClassName("input");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.borderColor = document.getElementById('color-box').value;
}
var x = document.getElementsByClassName("input");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.borderColor = document.getElementById("color-box").value;
}

document.getElementById('value-box').value = document.getElementById('color-box').value;
document.getElementById("value-box").value =
document.getElementById("color-box").value;
}

function check2() {
var x = document.getElementsByClassName("input");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.borderColor = document.getElementById('value-box').value;
}
var x = document.getElementsByClassName("input");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.borderColor = document.getElementById("value-box").value;
}

document.getElementById('color-box').value = document.getElementById('value-box').value;
}
document.getElementById("color-box").value =
document.getElementById("value-box").value;
}

function copyToClipboard() {
const copyHex = document.getElementById("value-box");
copyHex.addEventListener("change", updateValue);
function updateValue(e) {
copyHex.setAttibute("value", e.target.value);
}
const copyCode = copyHex.value;
navigator.clipboard.writeText(copyCode);

const tooltip = document.getElementById("copyTooltip");
tooltip.textContent = "Copied!";
tooltip.classList.add("slide-out-bck-center");
}

const copyButton = document.getElementById("copyButton");
copyButton.addEventListener("click", copyToClipboard);