Description
Is your feature request related to a problem? Please describe.
It seems like Svelte transitions require that the element be removed from the dom when it fades out and re-attached when it fades in.
I guess it's probably fine if the element is very simple, but usually, it's not. For example, whenever I just want to show/hide a complex sidebar menu, the dom contents of that menu have to be recreated every time it's displayed (and some other stuff like event listeners, js logic has to re-run, etc.).
Describe the solution you'd like
Extending Svelte transition API to allow to fade an element in/out of view without removing/re-attaching it. So for example, instead of removing the element, set a display: none;
style, or control the zIndex. (The latter would also be very nice, while we are at it, as in some extreme scenarios it's better performance if the element is already visible).
The ideal, most universal solution would be to let the user decide what should happen to the element on transitionStart / transitionEnd and allow that the element to stay without being removed.
So for example, this is how it's done now - the element will be removed:
{#if visible}
<p transition:fly="{{ y: 200, duration: 2000 }}">
Flies in and out
</p>
{/if}
This is how it could look like with controlling the display property - which would be done by supplying visible
property to transition properties:
<!--Supplying the `visible` property will make the element appear / disappear
using 'display: none' visibility-->
<p transition:fly="{{ visible, y: 200, duration: 2000 }}">
Flies in and out
</p>
Advanced usage: define the way in which the element should be shown/hidden.
<script>
const show = (el) => { el.style.zIndex = 10; }
const hide = (el) => { el.style.zIndex = -1; }
</script>
<!--Using show, hide properties means that the visibility of the element
is to be handled by the user (`display: none;` will not be applied)-->
<p transition:fly="{{ visible, show, hide, y: 200, duration: 2000, }}">
Flies in and out
</p>
Describe alternatives you've considered
Doing it manually, perhaps Svelte animations API could help (I haven't gotten to it yet).
How important is this feature to you?
Of medium importance. It means that I cannot use Svelte transitions API (which seems awesome). It also seems to be one of those rare cases where Svelte could use some performance optimization.