responsive!

This commit is contained in:
Hamcha 2024-10-31 23:50:00 +01:00
parent 7208b5d5c4
commit 1e5529838d
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89
2 changed files with 62 additions and 11 deletions

View file

@ -45,7 +45,7 @@ img.bg {
z-index: -1; z-index: -1;
filter: blur(20px); filter: blur(20px);
&.revealed { &.reveal {
filter: none; filter: none;
} }
} }
@ -56,6 +56,7 @@ h1 {
justify-content: center; justify-content: center;
margin-bottom: 10rem; margin-bottom: 10rem;
word-spacing: 10px; word-spacing: 10px;
padding: 0 2rem;
} }
.manacost { .manacost {
@ -82,7 +83,7 @@ h2 {
} }
.cardbox { .cardbox {
width: 50rem; max-width: 50rem;
text-align: left; text-align: left;
padding: 2rem; padding: 2rem;
background-color: rgba(2, 9, 23, 0.8); background-color: rgba(2, 9, 23, 0.8);
@ -105,6 +106,35 @@ h2 {
} }
} }
@media (max-width: 800px) {
.cardbox {
border-radius: 0;
}
main {
height: 100vh;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 100px;
h1 {
margin-bottom: 0;
flex-direction: column;
gap: 2rem;
}
.actions {
justify-self: center;
align-self: center;
button {
font-size: 1.2rem;
padding: 1rem 0.8rem;
}
}
}
}
.actions { .actions {
display: flex; display: flex;
gap: 1rem; gap: 1rem;

View file

@ -22,14 +22,31 @@ document.body.appendChild(main);
const cards = await loadCardData(); const cards = await loadCardData();
type Format = 'hiragana' | 'katakana'; type Format = 'hiragana' | 'katakana' | 'both';
const render = (format: Format, card_id?: number) => { const render = (format: Format, reveal = false, card_id?: number) => {
const index = card_id || Math.floor(Math.random() * cards.length); const index = card_id || Math.floor(Math.random() * cards.length);
const randomCard = cards[index]; const randomCard = cards[index];
const cardImage = $el('img.bg', { src: scryfallURL(randomCard.id) }); const cardImage = $el('img', {
const translate = className: `bg ${format}`,
format === 'hiragana' ? convert_to_hiragana : convert_to_katakana; src: scryfallURL(randomCard.id),
});
const translate = (text: string) => {
if (reveal) {
return text;
}
switch (format) {
case 'hiragana':
return convert_to_hiragana(text);
case 'katakana':
return convert_to_katakana(text);
case 'both':
if (Math.random() > 0.5) {
return convert_to_hiragana(text);
}
return convert_to_katakana(text);
}
};
main.remove(); main.remove();
main = $el( main = $el(
@ -58,14 +75,14 @@ const render = (format: Format, card_id?: number) => {
{ {
type: 'button', type: 'button',
'@click': () => { '@click': () => {
cardImage.classList.toggle('revealed'); render(format, !reveal, index);
}, },
}, },
translate('Rivela'), reveal ? 'Nascondi' : translate('Rivela'),
), ),
$el( $el(
'button', 'button',
{ type: 'button', '@click': () => render(format) }, { type: 'button', '@click': () => render(format, false) },
translate('Nuova carta'), translate('Nuova carta'),
), ),
$el( $el(
@ -73,7 +90,11 @@ const render = (format: Format, card_id?: number) => {
{ {
type: 'button', type: 'button',
'@click': () => { '@click': () => {
render(format === 'hiragana' ? 'katakana' : 'hiragana', index); render(
format === 'hiragana' ? 'katakana' : 'hiragana',
reveal,
index,
);
}, },
}, },
format === 'hiragana' format === 'hiragana'