Skip to content

Commit

Permalink
fix copy button animation
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Aug 12, 2021
1 parent f8aff7d commit b0cf35d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/assets/plugins/code-block/code-block.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
}

.markdown-section .docsify-copy-code-button.copied {
animation: pulse 1s;
animation: pulse 0.75s;
--pulse-color: rgb(var(--sl-color-neutral-500));
}

Expand Down
6 changes: 4 additions & 2 deletions docs/assets/plugins/code-block/code-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@
// Show pulse when copying
document.addEventListener('click', event => {
const button = event.target.closest('.docsify-copy-code-button');

if (button) {
button.classList.remove('copied');
requestAnimationFrame(() => button.classList.add('copied'));
requestAnimationFrame(() => {
button.addEventListener('animationend', () => button.classList.remove('copied'), { once: true });
button.classList.add('copied');
});
}
});
})();

0 comments on commit b0cf35d

Please sign in to comment.