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

102
Visualizações
JavaScript reading all 6 when 3 are hidden on mobile

My JavaScript function is reading all 6 total images and not 3 on mobile and 3 when desktop. My hidden-mobile and hidden-desktop CSS classes work totally fine and hide the images making the carousel scroll through all 6, showing three and other three blank. I'm very confused.

The HTML:

     <div class="parent hidden-mobile">
            <div class="mySlides fade image2">
                <img src="img/homebanner1.png" style="width:100%">
            </div>
            <div class="mySlides fade image2">
                <img src="img/homebanner2.png" style="width:100%">
            </div>
            <div class="mySlides fade image2">
                <img src="img/homebanner3.png" style="width:100%">
            </div>
        </div>

        <div class="parent hidden-desktop">
            <div class="mySlides fade image2">
                <img src="img/homebannermobile1.png" style="width:100%">
            </div>
            <div class="mySlides fade image2">
                <img src="img/homebannermobile2.png" style="width:100%">
            </div>
            <div class="mySlides fade image2">
                <img src="img/homebannermobile3.png" style="width:100%">
            </div>
        </div>

Javascript:

    var slideIndex = 0;
    showSlides();
    function showSlides() {
        var i;
        var slides = document.getElementsByClassName("mySlides");
        for(i = 0; i < slides.length; i++) {
        slides[i].style.display = "none";
        }
        slideIndex++;
        if(slideIndex > slides.length) {
        slideIndex = 1
        }
        slides[slideIndex - 1].style.display = "block";
        setTimeout(showSlides, 10000); // Change image every 10 seconds
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can add a media query to you css which will hide three at a certain screen size:

@media only screen and (max-width: 640px) {
  .parent hidden-desktop{
    display: none;
  }
}
@media only screen and (min-width: 640px) {
  .parent hidden-mobile{
    display: none;
  }
}

But you will need to add the class parent hidden-mobile like you did for the desktop with "parent hidden-desktop".

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