Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
Adding Alpinejs Transition Effect after updating "x-text" value

I am trying to build a simple slider with alpinejs and tailwindcss. We have a very simple code which slide in two array values (I am going to make it a product slider):

simple slider Later its gonna be like: enter image description here

<div x-data="{ activeSlide: 1, slides: [1, 2, 3, 4, 5], text: ['a', 'b', 'c', 'd', 'e'] }">
  previous item
  <div x-text="text[activeSlide-2] ? text[activeSlide-2] : text[slides.length-1]"></div>
  
  <div class="my-5 border border-black">
    current item

  <div class="font-bold" x-text="activeSlide"></div>
  <div class="font-bold"  x-text="text[activeSlide-1]"></div>
  </div>
  next item
  <div x-text="text[activeSlide] ? text[activeSlide] : text[0]"></div>


  <div class="mt-5">
    <button x-on:click='activeSlide= activeSlide === 1 ? slides.length : activeSlide - 1'>Prev</button>
    <button x-on:click='activeSlide= activeSlide === slides.length ? 1 : activeSlide + 1'>Next</button>
  </div>
</div>

The problem is I want to add some transition effect when updating x-text values (when changing slides) and x-transition is for x-show or ... not for updating the x-text value.

Could you please guide me, how can I add some effects when changing the values of x-text? later its gonna be images src and I want to kind of refresh the whole card (slide)

Many thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think I should do something like

    <div x-data="{ activeSlide: 1, slides: [1, 2, 3, 4, 5], text: ['a', 'b', 'c', 'd', 'e'] }">
        <template x-for="slide in slides" :key="slide">
            <div x-show="activeSlide === slide">
                ...

And it must be okay to use x-transition because x-show is changing...

First example that I found was this way, but I wanted to avoid duplication (It will render everything nth time! and I think its not good). I wanted to avoid Rendering All the cards and hide them, I wanted to just pass and change the data so I came up with the code in the question.

So if anyone has a way to use the code in the question and add transition to it, I will appreciate it!

Thanks again

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda