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

133
Visualizações
Automatic Carousel with Dom manipulation

I want to change the order of my child divs in the parent div, every 2 seconds with no interactions (rotate by its self if page is loaded:

First child needs to move to third child, second child needs to move to the first child and the third child needs to move to the second child

The second and third child should always have the class "small" and when it reach the first child position it should be removed.

HTML

     <div class="inner-testimonial">        
         <div class="slide">
             <h4>Copy here</h4>
         </div>
         <div class="slide small">
             <h4>Copy here</h4>
         </div>
         <div class="slide small">
             <h4>Copy here</h4>
         </div>
      </div>

JQuery

$(".inner-testimonial .slide:nth-child(1)").removeClass('small');
$(".inner-testimonial .slide:nth-child(2)").addClass('small');
$(".inner-testimonial .slide:nth-child(3)").addClass('small');

How can I do this?

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

0

You can do it like this :

  1. Remove small class for all slides with removeClass()
  2. Set different var with each slides positions
  3. Set slides container empty with empty()
  4. Append slides in right order with append()
  5. And then add all of this inside a setInterval() called every 2 seconds.

Order of first change will be : 2 3 1
Order of second change will be : 3 1 2
And then order will return to its initial point : 1 2 3

Thanks to validate and upvote my answer if it do what you expect.

setInterval(function () {
  // remove small class for all slides
  $('.inner-testimonial .slide').removeClass("small");

  // set different var with each slides positions
  var firstEl = $('.inner-testimonial .slide:first');
  var secondEl = $('.inner-testimonial .slide:first').next();
  var thirdEl = $('.inner-testimonial .slide:last');

  // set slides container empty
  $('.inner-testimonial').empty();

  // append slides in right order : secondEl + thirdEl + firstEl
  $('.inner-testimonial').append(secondEl);
  $('.inner-testimonial').append($(thirdEl).addClass("small"));
  $('.inner-testimonial').append($(firstEl).addClass("small"));
}, 2000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="inner-testimonial"> 
  <div id="first"></div>
   <div class="slide">
       <h4>First</h4>
   </div>
   <div class="slide small">
       <h4>Second</h4>
   </div>
   <div class="slide small">
       <h4>Third</h4>
   </div>
</div>

<div id="test"></div>

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