Skip to content

Commit e24bf1b

Browse files
committed
optimize: copy button transition
1 parent 53e28d6 commit e24bf1b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lib/ZMD/ZPre.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
let visibility = $state('hidden');
1515
let hint = $state('');
1616
let disabled = $state(false);
17+
let delay = $state('0s');
1718
1819
async function copyContent() {
1920
try {
@@ -22,13 +23,15 @@
2223
visibility = 'visible';
2324
hint = '复制!';
2425
disabled = true;
26+
delay = '1500ms';
2527
2628
setTimeout(() => {
2729
icon = 'copy';
2830
visibility = 'hidden';
2931
hint = '';
3032
disabled = false;
31-
}, 1800);
33+
delay = '0s';
34+
}, 2000);
3235
} catch (err) {
3336
console.error('复制失败:', err);
3437
}
@@ -39,7 +42,7 @@
3942
<pre contenteditable="false" bind:innerText={content}><code
4043
class={$ast.children[0].properties?.class}><ZPreCode ast={$ast.children[0]}></ZPreCode></code
4144
></pre>
42-
<button {disabled} class="copyBtn" onclick={copyContent}>
45+
<button {disabled} class="copyBtn" style="--delay:{delay};" onclick={copyContent}>
4346
<span style="visibility: {visibility};" class="hint">{hint}</span>
4447
<ZIcon height="1.5rem" width="1.5rem" option={icon}></ZIcon>
4548
</button>
@@ -62,7 +65,7 @@
6265
box-sizing: border-box;
6366
padding: 0.2rem;
6467
opacity: 0;
65-
transition: opacity 0.3s 1s ease;
68+
transition: opacity 0.3s var(--delay) ease;
6669
&:hover {
6770
cursor: pointer;
6871
path {

0 commit comments

Comments
 (0)