Add flip animation on note list

This commit is contained in:
Dallas Hoffman 2023-10-17 23:20:58 -04:00
parent 551b564a42
commit 7342c18c00
No known key found for this signature in database
1 changed files with 19 additions and 2 deletions

View File

@ -2,6 +2,7 @@
import NoteCard from '$lib/components/notes/note-card.svelte'; import NoteCard from '$lib/components/notes/note-card.svelte';
import { notes, settings } from '$lib/stores'; import { notes, settings } from '$lib/stores';
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { flip } from 'svelte/animate';
import { get, type Unsubscriber } from 'svelte/store'; import { get, type Unsubscriber } from 'svelte/store';
let noteListElement: HTMLUListElement; let noteListElement: HTMLUListElement;
@ -10,6 +11,7 @@
const paddingRows = 2; const paddingRows = 2;
let scrollHeight = 0; let scrollHeight = 0;
let scrollOffset = 0; let scrollOffset = 0;
let flipDuration = 0;
let notesOffset = 0; let notesOffset = 0;
let notesLimit = 100; let notesLimit = 100;
@ -37,6 +39,13 @@
Math.min(notesCount - offset, Math.ceil(windowHeight / rowHeight) + paddingRows * 2) * Math.min(notesCount - offset, Math.ceil(windowHeight / rowHeight) + paddingRows * 2) *
columnCount; columnCount;
if (notesCount !== prevNotesCount) {
flipDuration = 300;
setTimeout(() => {
flipDuration = 0;
}, 300);
}
if ( if (
offset === notesOffset && offset === notesOffset &&
limit === notesLimit && limit === notesLimit &&
@ -80,7 +89,11 @@
style:--scroll-offset={`translateY(${scrollOffset}px)`} style:--scroll-offset={`translateY(${scrollOffset}px)`}
> >
{#each $notes as note (note.id)} {#each $notes as note (note.id)}
<li> <li
class="note-list__item"
class:note-list__item--no-flip={flipDuration === 0}
animate:flip={{ duration: flipDuration }}
>
<NoteCard {note} /> <NoteCard {note} />
</li> </li>
{/each} {/each}
@ -97,11 +110,15 @@
padding: 0; padding: 0;
margin: 0; margin: 0;
li { &__item {
list-style-type: none; list-style-type: none;
margin: 0; margin: 0;
transform: var(--scroll-offset, none); transform: var(--scroll-offset, none);
&--no-flip {
animation: none !important;
}
&:has(.bytemd-fullscreen) { &:has(.bytemd-fullscreen) {
transform: none; transform: none;
} }