Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!