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

163
Visualizações
classList.toggle for several elements Javascript

I designed a vertical slide from bottom navigation on mobile. I would like each tab could move (up or down) with the upper one. May be the toggle method isn't the right one. I use vanilla JS.

Here is my function. The two last lines are to show the idea. I would like to write it in a better way.

let children = document.getElementById('mobile-container').children;

for (let i = 0; i < children.length; i++) {
    children[i].addEventListener("touchstart", function () {
        children[i].classList.toggle("unfold");
        children[i-1].classList.toggle("unfold");
        children[i-2].classList.toggle("unfold");
    });
}

Here is my HTML

<div id="mobile-container">
                <div id="mobile-projets" class="mobile">
                    <h2>Projets</h2>
                </div>
                <div id="mobile-expertises" class="mobile">
                    <h2>Expertises</h2>
                </div>
                <div id="mobile-clients" class="mobile">
                    <h2>Clients</h2>
                </div>
</div>

Here is my CSS

 #mobile-container {
        display: block;
        position: relative;
        width: 100%;
        height: 85vh;
        top: 15vh;
    }

    #mobile-projets {
        width:100%;
        height: 100%;
        background: #00A6C6;
        text-align: center;
        border-radius: 1em 1em 0 0;
        position: absolute;
        top: 69vh;
    }   

    #mobile-expertises {
        width:100%;
        height: 95%;
        background: #FFFFFF;
        color: black;
        text-align: center;
        border-radius: 1em 1em 0 0;
        position: absolute;
        top: 74vh;
    } 

    #mobile-clients {
        width:100%;
        height: 90%;
        background: #00A6C6;
        text-align: center;
        border-radius: 1em 1em 0 0;
        position: absolute;
        top: 79vh;
    }
    
    #mobile-projets.unfold {
        top: 0;
        transition: all 1s ease;
        -webkit-transition: all 1s easeout;
        -moz-transition: all 1s easeout;
        -ms-transition: all 1s easeout;
        -o-transition: all 1s easeout;
    }

    #mobile-expertises.unfold {
        top: 5vh;
        transition: all 1s ease;
        -webkit-transition: all 1s easeout;
        -moz-transition: all 1s easeout;
        -ms-transition: all 1s easeout;
        -o-transition: all 1s easeout;
    }

    #mobile-clients.unfold {
        top: 10vh;
        transition: all 1s ease;
        -webkit-transition: all 1s easeout;
        -moz-transition: all 1s easeout;
        -ms-transition: all 1s easeout;
        -o-transition: all 1s easeout;
    }
about 4 years ago · Juan Pablo Isaza
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