Skip to content

Commit 84c3741

Browse files
added Smooth Transitions for letters and answers
1 parent f21b2ff commit 84c3741

2 files changed

Lines changed: 93 additions & 25 deletions

File tree

script.js

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ let romajiButton = document.getElementById("romaji");
66
const blockquote = document.getElementById('letter');
77
const answer = document.getElementById('answer');
88
let main = document.getElementById('main');
9+
const instructionText = document.querySelector('.main p');
910

1011
let ind = Math.floor(Math.random() * kanaList.length);
1112

1213
document.addEventListener("DOMContentLoaded", () => {
1314
const savedMode = localStorage.getItem('kanaMode');
1415

16+
instructionText.textContent = "Click to reveal";
17+
1518
if (savedMode === 'katakana') {
1619
katakanaButton.click();
1720
} else if (savedMode === 'romaji') {
@@ -28,6 +31,7 @@ hiraganaButton.addEventListener("click", () => {
2831
answer.classList.remove('shown');
2932
hiraganaButton.classList.toggle('clicked');
3033
blockquote.textContent = kanaList[ind][0];
34+
instructionText.textContent = "Click to reveal";
3135
}
3236
katakanaButton.classList.remove('clicked');
3337
romajiButton.classList.remove('clicked');
@@ -40,6 +44,7 @@ katakanaButton.addEventListener("click", () => {
4044
answer.classList.remove('shown');
4145
katakanaButton.classList.toggle('clicked');
4246
blockquote.textContent = kanaList[ind][1];
47+
instructionText.textContent = "Click to reveal";
4348
}
4449
hiraganaButton.classList.remove('clicked');
4550
romajiButton.classList.remove('clicked');
@@ -52,6 +57,7 @@ romajiButton.addEventListener("click", () => {
5257
answer.classList.remove('shown');
5358
romajiButton.classList.toggle('clicked');
5459
blockquote.textContent = kanaList[ind][2];
60+
instructionText.textContent = "Click to reveal";
5561
}
5662
hiraganaButton.classList.remove('clicked');
5763
katakanaButton.classList.remove('clicked');
@@ -60,23 +66,42 @@ romajiButton.addEventListener("click", () => {
6066
main.addEventListener("click", () => {
6167
if(!answer.classList.contains('shown')){
6268
answer.classList.add('shown');
69+
instructionText.textContent = "Click for next";
6370
}
6471
else{
65-
answer.classList.remove('shown');
66-
ind = Math.floor(Math.random() * kanaList.length);
67-
68-
if(hiraganaButton.classList.contains('clicked')){
69-
blockquote.textContent = kanaList[ind][0];
70-
answer.textContent = kanaList[ind][2];
71-
}
72-
else if(katakanaButton.classList.contains('clicked')){
73-
blockquote.textContent = kanaList[ind][1];
74-
answer.textContent = kanaList[ind][2];
75-
}
76-
else{
77-
blockquote.textContent = kanaList[ind][2];
78-
answer.textContent = kanaList[ind][0] + " " + kanaList[ind][1];
79-
}
72+
blockquote.classList.add('fade-out');
73+
answer.classList.add('fade-out');
74+
instructionText.classList.add('fade-out');
75+
76+
setTimeout(() => {
77+
ind = Math.floor(Math.random() * kanaList.length);
78+
79+
answer.style.transition = 'none';
80+
answer.classList.remove('shown');
81+
82+
instructionText.textContent = "Click to reveal";
83+
84+
if(hiraganaButton.classList.contains('clicked')){
85+
blockquote.textContent = kanaList[ind][0];
86+
answer.textContent = kanaList[ind][2];
87+
}
88+
else if(katakanaButton.classList.contains('clicked')){
89+
blockquote.textContent = kanaList[ind][1];
90+
answer.textContent = kanaList[ind][2];
91+
}
92+
else{
93+
blockquote.textContent = kanaList[ind][2];
94+
answer.textContent = kanaList[ind][0] + " " + kanaList[ind][1];
95+
}
96+
97+
void answer.offsetWidth;
98+
99+
answer.style.transition = '';
100+
101+
blockquote.classList.remove('fade-out');
102+
answer.classList.remove('fade-out');
103+
instructionText.classList.remove('fade-out');
104+
}, 100);
80105
}
81106
})
82107

style.css

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
* {
2-
box-sizing: border-box;
2+
box-sizing: border-box;
33
}
44

55
::-webkit-scrollbar {
@@ -15,6 +15,21 @@
1515
--text-hover: #ffffff;
1616
}
1717

18+
body:focus-visible {
19+
outline: none;
20+
}
21+
22+
html:focus-visible {
23+
outline: none;
24+
}
25+
26+
button:focus-visible,
27+
a:focus-visible,
28+
.main:focus-visible {
29+
outline: none;
30+
outline-offset: none;
31+
}
32+
1833
html, body {
1934
margin: 0;
2035
padding: 0;
@@ -85,7 +100,7 @@ html, body {
85100
width: 24px;
86101
height: 24px;
87102
transition: transform 0.2s ease;
88-
display: block;
103+
display: block;
89104
}
90105

91106
.github svg {
@@ -130,7 +145,6 @@ html, body {
130145
appearance: none;
131146
-webkit-appearance: none;
132147
-moz-appearance: none;
133-
134148
align-items: center;
135149
justify-content: center;
136150
display: flex;
@@ -146,18 +160,24 @@ html, body {
146160
transition: all 0.2s ease-in-out;
147161
margin: 0;
148162
padding: 0;
163+
box-shadow: 0px 4px 0px rgba(0,0,0,0.2);
149164
}
150165

151166
.buttons button:hover {
152167
cursor: pointer;
153168
background-color: #262a2b;
154-
transform: scale(1.05);
155169
}
156170

157171
.buttons button:active {
158172
transform: scale(0.95);
159173
}
160174

175+
.buttons button:active,
176+
.buttons button.clicked {
177+
transform: translateY(2px) scale(0.98);
178+
box-shadow: 0px 1px 0px rgba(0,0,0,0.2);
179+
}
180+
161181
#hiragana.clicked,
162182
#katakana.clicked,
163183
#romaji.clicked {
@@ -193,10 +213,19 @@ html, body {
193213
align-items: center;
194214
justify-content: center;
195215
display: flex;
196-
font-size: 100px;
216+
font-size: 100px;
197217
font-size: clamp(80px, 25vw, 150px);
198218
}
199219

220+
#letter {
221+
font-family: "Zen Maru Gothic", sans-serif;
222+
}
223+
224+
#letter.fade-out {
225+
opacity: 0;
226+
transform: scale(0.9);
227+
}
228+
200229
.submain {
201230
display: flex;
202231
flex-direction: column;
@@ -213,23 +242,37 @@ html, body {
213242
display: flex;
214243
align-items: center;
215244
justify-content: center;
245+
border-radius: 10px;
246+
border: 2px dashed rgba(255, 255, 255, 0.1);
247+
}
248+
249+
#answer.fade-out {
250+
opacity: 0;
251+
transform: scale(0.9);
216252
}
217253

218254
#answer.shown {
219-
transition: ease 0.2s;
220255
text-align: center;
221256
padding: 0 15px;
222257
font-size: 25px;
223258
font-family: "Comic Neue", sans-serif;
224259
color: white;
225260
background-color: var(--buttons);
226-
border-radius: 10px;
227261
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
262+
border: 2px solid var(--buttons);
228263
}
229264

230-
#letter {
231-
transition: all ease 0.2s;
232-
font-family: "Zen Maru Gothic", sans-serif;
265+
.main p,
266+
#letter,
267+
#answer {
268+
transition: opacity 0.15s ease-out, transform 0.15s ease-out;
269+
opacity: 1;
270+
transform: scale(1);
271+
}
272+
273+
.fade-out {
274+
opacity: 0 !important;
275+
transform: scale(0.9) !important;
233276
}
234277

235278
@media (max-width: 600px) {

0 commit comments

Comments
 (0)