Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
How do you fade in a div in Svelte when content change?

How do you fade in a div in Svelte when content change? I have one list for published texts and another for drafts. I know how to do it with plain javascript but is there a solution for this in svelte besides when a page is loaded?

async function published() {
    lipub.style.backgroundColor = "#CCC";
    lidraft.style.backgroundColor = "transparent";
    const response = await fetch("api/mytexts/?id=" + $session.userID);
    result = await response.json();
    return result;
  }

  async function drafts() {
    lipub.style.backgroundColor = "transparent";
    lidraft.style.backgroundColor = "#CCC";
    const response = await fetch("api/mytexts/drafts?id=" + $session.userID);
    result = await response.json();
    return result;
  }

<div>
<div id="headerblock" style="cursor: default;">
    <ul id="headermenu">
      <li class="selected" on:click={published} bind:this={lipub}>Published</li>
      <li on:click={drafts} bind:this={lidraft}>Drafts</li>
      <li on:click={newtext}>{$_("page.newtext.title")}</li>
    </ul>
  </div>

    {#if result}

      <div fade-in-this-when-new-result>

      {#each result as text}
        <div class="block" on:click={() => readData(text.id)}>
          <span class="istext">{text.title}</span>
        </div>
      {/each}

     </div>

    {/if}

</div>

EDIT It works when I reset result in between.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can cause a block to be re-created, triggering transitions using {#key}, e.g.

{#key list}
    <div in:fade={{ duration: 300 }}>
        {#each list as item}
            <div>{item}</div>
        {/each}
    </div>
{/key}

REPL

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda