Card is now fully loaded in itself

No longer do we have this weird shift of the description to the right of
the Card until some magical JS is loaded to fix it.
Not yet perfect: The now wrapping a-tag is for some reason still weirdly
sent to client until some js cleans it up. Currently results in a too
large gap which is fixed by local js.

Still TODO: do not blur images if no js present
This commit is contained in:
Alexander Bocken 2024-01-22 14:13:56 +01:00
parent 0f45145119
commit 7ec94246f0
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8

View File

@ -14,22 +14,27 @@ if(icon_override){
let isloaded = false let isloaded = false
import { onMount } from "svelte"; import { onMount } from "svelte";
onMount(() => {
isloaded = document.querySelector("img")?.complete ? true : false onMount(() => {
}) isloaded = document.querySelector("img")?.complete ? true : false
})
</script> </script>
<style> <style>
#card{ .card_anchor{
border-radius: 20px;
}
.card{
--card-width: 300px; --card-width: 300px;
position: relative;
flex-shrink: 0; flex-shrink: 0;
transition: 200ms; transition: 200ms;
text-decoration: none; text-decoration: none;
position: relative;
box-sizing: border-box; box-sizing: border-box;
font-family: sans-serif; font-family: sans-serif;
cursor: pointer; cursor: pointer;
height: calc(7/4 * var(--card-width)); /* otherwise card is not initialized at correct size and readjusts when populated*/ height: 525px;
width: var(--card-width); width: 300px;
border-radius: 20px; border-radius: 20px;
background-size: contain; background-size: contain;
display: flex; display: flex;
@ -39,8 +44,8 @@ import { onMount } from "svelte";
box-shadow: 0em 0em 2em 0.1em rgba(0, 0, 0, 0.3); box-shadow: 0em 0em 2em 0.1em rgba(0, 0, 0, 0.3);
} }
#image{ #image{
width: var(--card-width); width: 300px;
height: calc(var(--card-width)*0.85); height: 255px;
object-fit: cover; object-fit: cover;
transition: 200ms; transition: 200ms;
filter: blur(10px); filter: blur(10px);
@ -49,9 +54,9 @@ import { onMount } from "svelte";
.unblur{ .unblur{
filter: blur(0px) !important; filter: blur(0px) !important;
} }
#div_image, .div_image,
#div_div_image{ .div_div_image{
width: var(--card-width); width: 300px;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: cover; background-size: cover;
background-position: center; background-position: center;
@ -59,27 +64,28 @@ import { onMount } from "svelte";
border-top-left-radius: inherit; border-top-left-radius: inherit;
border-top-right-radius: inherit; border-top-right-radius: inherit;
} }
#div_div_image{ .div_div_image{
height: calc(var(--card-width)*0.85); height: 255px;
position: absolute; position: absolute;
width: var(--card-width); width: 300px;
top: 0; top: 0;
} }
#card:hover, .card:hover,
#card:focus-within{ .card:focus-within{
transform: scale(1.02,1.02); transform: scale(1.02,1.02);
background-color: var(--red); background-color: var(--red);
box-shadow: 0.2em 0.2em 2em 1em rgba(0, 0, 0, 0.3); box-shadow: 0.2em 0.2em 2em 1em rgba(0, 0, 0, 0.3);
} }
#card:focus{ .card:focus{
scale: 0.95 0.95; scale: 0.95 0.95;
} }
.title { .card_title {
position: relative; position: absolute;
padding-top: 0.5em; padding-top: 0.5em;
height: 50%; height: 262.5px;
width: 100% ; width: 300px;
top: 262.5px;
border-bottom-left-radius: inherit; border-bottom-left-radius: inherit;
border-bottom-right-radius: inherit; border-bottom-right-radius: inherit;
display: flex; display: flex;
@ -130,7 +136,7 @@ import { onMount } from "svelte";
transition: 100ms; transition: 100ms;
scale: 0.9; scale: 0.9;
} }
.title .category{ .card_title .category{
position: absolute; position: absolute;
box-shadow: 0em 0em 1em 0.1em rgba(0, 0, 0, 0.6); box-shadow: 0em 0em 1em 0.1em rgba(0, 0, 0, 0.6);
text-decoration: none; text-decoration: none;
@ -144,8 +150,8 @@ import { onMount } from "svelte";
transition: 100ms; transition: 100ms;
} }
.title .category:hover, .card_title .category:hover,
.title .category:focus-within .card_title .category:focus-within
{ {
box-shadow: -0.2em 0.2em 1em 0.1em rgba(0, 0, 0, 0.6); box-shadow: -0.2em 0.2em 1em 0.1em rgba(0, 0, 0, 0.6);
background-color: var(--nord3); background-color: var(--nord3);
@ -155,24 +161,24 @@ import { onMount } from "svelte";
scale: 0.9 0.9; scale: 0.9 0.9;
} }
#card:hover .icon, .card:hover .icon,
#card:focus-visible .icon .card:focus-visible .icon
{ {
animation: shake 0.6s; animation: shake 0.6s;
} }
</style> </style>
<a id="card" class:search_me={search} href="/rezepte/{recipe.short_name}" data-tags=[{recipe.tags}]> <a class=card_anchor href="/rezepte/{recipe.short_name}">
<div id=div_div_image > <div class="card" class:search_me={search} data-tags=[{recipe.tags}]>
<div id=div_image style="background-image:url({'https://bocken.org/static/rezepte/placeholder/' + recipe.short_name + '.webp'})"> <div class=div_div_image >
<div class=div_image style="background-image:url({'https://bocken.org/static/rezepte/placeholder/' + recipe.short_name + '.webp'})">
<img class:unblur={isloaded} id=image src={'https://bocken.org/static/rezepte/thumb/' + recipe.short_name + '.webp'} loading=lazy alt="{recipe.alt}" on:load={() => isloaded=true}/> <img class:unblur={isloaded} id=image src={'https://bocken.org/static/rezepte/thumb/' + recipe.short_name + '.webp'} loading=lazy alt="{recipe.alt}" on:load={() => isloaded=true}/>
</div> </div>
</div> </div>
{#if icon_override || recipe.season.includes(current_month)} {#if icon_override || recipe.season.includes(current_month)}
<a class=icon href="/rezepte/icon/{recipe.icon}">{recipe.icon}</a> <a class=icon href="/rezepte/icon/{recipe.icon}">{recipe.icon}</a>
{/if} {/if}
<div class="card_title">
<div class=title>
<a class=category href="/rezepte/category/{recipe.category}" >{recipe.category}</a> <a class=category href="/rezepte/category/{recipe.category}" >{recipe.category}</a>
<div> <div>
<div class=name>{@html recipe.name}</div> <div class=name>{@html recipe.name}</div>
@ -184,4 +190,5 @@ import { onMount } from "svelte";
{/each} {/each}
</div> </div>
</div> </div>
</div>
</a> </a>