Disable copy button until animation completes, fix the fill animation color, change how animations/transitions are disabled

This commit is contained in:
daudix
2024-09-02 03:25:26 +03:00
parent 1b0bcfba93
commit fe1ec83a28
5 changed files with 24 additions and 20 deletions

View File

@ -36,22 +36,24 @@
container.appendChild(block);
button.addEventListener("click", async () => {
await copyCode(block, header);
await copyCode(block, header, button); // Pass the button here
});
}
});
async function copyCode(block, header) {
async function copyCode(block, header, button) {
let code = block.querySelector("code");
let text = code.innerText;
await navigator.clipboard.writeText(text);
header.classList.add("active");
button.setAttribute("disabled", true);
setTimeout(() => {
header.addEventListener("animationend", () => {
header.classList.remove("active");
}, 800);
button.removeAttribute("disabled");
}, { once: true });
}
});
</script>