Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Svelte 3 Up and Running

You're reading from   Svelte 3 Up and Running A fast-paced introductory guide to building high-performance web applications with SvelteJS

Arrow left icon
Product type Paperback
Published in Aug 2020
Publisher Packt
ISBN-13 9781839213625
Length 168 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Alessandro Segala Alessandro Segala
Author Profile Icon Alessandro Segala
Alessandro Segala
Arrow right icon
View More author details
Toc

Transitions

Our app looks great already, but we could improve the user experience a bit with some transitions between the various views. With Svelte, this is available within the framework itself.

Svelte transitions

Svelte offers multiple pre-made transitions in the svelte/transition package. As of writing, there are six of them: blur, draw, fade, fly, and scale, slide. We will leave it as an exercise to the reader to try them and see their behavior!

Applying transitions

Transitions can only be applied to elements (that is, HTML tags) and not to Svelte components.

To make a DOM element transition nicely when appearing or disappearing, we just need to add a transition: property to its tag, followed by the name of the transition function. For example, take this snippet:

<button on:click={() => show = !show}>Click me</button>
{#if show}<p transition:blur>Hello world!</p>{/if}
<script>
import {blur} from 'svelte/transition'...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime