Skip to content

Commit deea5ab

Browse files
committed
feat: button fade
1 parent e724900 commit deea5ab

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/posts/text_manipulation.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</code>
1111

1212
<input type="button" value="Copy" id="copyBtn">
13+
<span id="feedback"></span>
1314

1415
<script>
1516
const input = document.getElementById('input');
@@ -55,21 +56,31 @@
5556
output.textContent = getAlgo()(input.value);
5657
});
5758

59+
var lastFeedbackFade = null;
5860
document.getElementById('copyBtn').addEventListener('click', () => {
61+
if (lastFeedbackFade) {
62+
clearTimeout(lastFeedbackFade);
63+
}
5964
navigator.clipboard.writeText(output.textContent);
65+
const feedback = document.getElementById('feedback');
66+
feedback.textContent = 'Copied at ' + new Date().toLocaleTimeString();
67+
lastFeedbackFade = setTimeout(() => {
68+
feedback.textContent = "";
69+
}, 2000);
6070
});
6171
</script>
6272

6373
<style>
6474
textarea#input {
75+
display: block;
6576
width: 100%;
6677
min-height: 6em;
6778
background-color: #202;
6879
border: #fdf 1px solid;
6980
border-radius: 1em;
7081
padding: 1em 1em;
7182
color: #fdf;
72-
margin-bottom: 0.5em;
83+
margin-bottom: 1em;
7384
resize: vertical;
7485
}
7586
#outputWrap {
@@ -81,20 +92,32 @@
8192
padding: 1em 1em;
8293
margin-top: 1em;
8394
}
95+
#output {
96+
text-wrap: pretty;
97+
overflow-wrap: break-word;
98+
}
8499
#copyBtn {
85-
display: block;
100+
display: inline-block;
86101
margin-top: 1em;
87102
background-color: #fdf;
88103
border: none;
89-
color: #000;
104+
color: #101;
90105
padding: .1em .5em;
91106
border-radius: .5em;
107+
cursor: pointer;
108+
}
109+
#copyBtn:hover {
110+
background-color: #fff;
92111
}
93112
#algo {
94113
background-color: #fdf;
95114
border: none;
96-
color: #000;
115+
color: #101;
97116
padding: .1em .5em;
98117
border-radius: .5em;
118+
cursor: pointer;
119+
}
120+
#algo:hover {
121+
background-color: #fff;
99122
}
100123
</style>

0 commit comments

Comments
 (0)