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

103
Vistas
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 Respuestas
Responde la pregunta

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 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