The images on the right are transitioning between slides, but the ones on the left seem to be frozen on the

https://i.sstatic.net/qKwbP.jpgI am experiencing an issue with my two changing image galleries placed side by side. The right image gallery is functioning properly and switching slides, but the left one seems to be stuck on the first slide. I sourced the code from W3.CSS, modified the classes "changing-photo-right" and "changing-photo-left" to my own custom class (available in my CSS stylesheet), and excluded the link to the W3.css stylesheet.

.section2 {
  background: #F5DAD3;
  display: flex;
  height: 750px; 
  position: relative;
}


.changing-photo-left {
  float: left;
  margin-left: 125px;
  margin-top: -390px;
  position: relative;
  display: block;
}

.changing-photo-right {
  float: right;
  margin-right: 125px;
  margin-top: -390px;
  position: relative;
  display: block;
}



.section3 {
  height: 440px;
  width: 2px; 
  top: 160px;
  left: 50%;
  position: absolute;
  border: 0px solid black;
  background-color: black;
  border-radius: 20px;
}
 <div class="hmm">
            <div class="section2"></div>
            <div class="section3" ></div>
            <div>
                <p class="text-12">The interieur</p>
                <p class="text-11">Discover the lovely interieur that was built since 1948.</p>
                <a class="button-intro-below-left" href="">Click here for more</a>
                <div class="changing-photo-left" style="max-width:500px">
                    <img class="mySlides" src="009.jpg" style="width:100%">
                    <img class="mySlides" src="062.jpg" style="width:100%">
                    <img class="mySlides" src="027.jpg" style="width:100%">
                </div>
                  
                  <script>
                  var myIndex = 0;
                  carousel();
                  
                  function carousel() {
                    var i;
                    var x = document.getElementsByClassName("mySlides");
                    for (i = 0; i < x.length; i++) {
                      x[i].style.display = "none";  
                    }
                    myIndex++;
                    if (myIndex > x.length) {myIndex = 1}    
                    x[myIndex-1].style.display = "block";  
                    setTimeout(carousel, 2500); // Change image every 3 seconds
                  }
                  </script>
            </div>

            <div>
                <p class="text-13">The exterior</p>
                <p class="text-14">Discover the lovely exterior that was built since 1948.</p>
                <a class="button-intro-below-right" href="">Click here for more</a>
                <div class="changing-photo-right" style="max-width:500px">
                    <img class="mySlides1" src="009.jpg" style="width:100%">
                    <img class="mySlides1" src="012.jpg" style="width:100%">
                    <img class="mySlides1" src="013.jpg" style="width:100%">
                </div>

                <script>
                    var myIndex = 0;
                    carousel();
                    
                    function carousel() {
                      var i;
                      var x = document.getElementsByClassName("mySlides1");
                      for (i = 0; i < x.length; i++) {
                        x[i].style.display = "none";  
                      }
                      myIndex++;
                      if (myIndex > x.length) {myIndex = 1}    
                      x[myIndex-1].style.display = "block";  
                      setTimeout(carousel, 2500); // Change image every 3 seconds
                    }
                    </script>

            </div>

Answer №1

Using identical names for the variables and functions in both loops can cause issues. To resolve this, consider altering the names of the variables and functions in the second loop.

.section2 {
    background: #F5DAD3;
    display: flex;
    height: 750px; 
    position: relative;
  }
  
  
  .changing-photo-left {
    float: left;
    margin-left: 125px;
    margin-top: -390px;
    position: relative;
    display: block;
  }
  
  .changing-photo-right {
    float: right;
    margin-right: 125px;
    margin-top: -390px;
    position: relative;
    display: block;
  }
  
  
  
  .section3 {
    height: 440px;
    width: 2px; 
    top: 160px;
    left: 50%;
    position: absolute;
    border: 0px solid black;
    background-color: black;
    border-radius: 20px;
  }
    <div class="hmm">
        <div class="section2"></div>
        <div class="section3" ></div>
        <div>
            <p class="text-12">The interior</p>
            <p class="text-11">Explore the charming interior that has been around since 1948.</p>
            <a class="button-intro-below-left" href="">Find out more here</a>
            <div class="changing-photo-left" style="max-width:500px">
                <img class="mySlides" src="https://images.unsplash.com/photo-1672426142068-c2103a852426?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzfHx8ZW58MHx8fHw%3D&w=1000&q=80" style="width:100%">
                <img class="mySlides" src="https://media.istockphoto.com/id/1409254639/photo/autumn-drive.jpg?b=1&s=170667a&w=0&k=20&c=phQOICvfLifPWESZu3AioY7sKM9s_HQnCozMKF6g120=" style="width:100%">
                <img class="mySlides" src="https://media.istockphoto.com/id/1427249962/photo/tropical-leaves-abstract-green-leaf-texture-in-garden-nature-background.jpg?b=1&s=170667a&w=0&k=20&c=40KcV7mbAQWihuO0At8GSOTIKp-TvIoHGIhurHBeUq0=" style="width:100%">
            </div>
              
              <script>
                var myIndex = 0;
                carousel();
                
                function carousel() {
                  var i;
                  var x = document.getElementsByClassName("mySlides");
                  for (i = 0; i < x.length; i++) {
                    x[i].style.display = "none";  
                  }
                  myIndex++;
                  if (myIndex > x.length) {myIndex = 1}    
                  x[myIndex-1].style.display = "block";  
                  setTimeout(carousel, 2500); // Change image every 3 seconds
                }
              </script>
        </div>

        <div>
            <p class="text-13">The exterior</p>
            <p class="text-14">Discover the lovely exterior that was built since 1948.</p>
            <a class="button-intro-below-right" href="">Click here for more</a>
            <div class="changing-photo-right" style="max-width:500px">
                <img class="mySlides1" src="https://images.unsplash.com/photo-1672426142068-c2103a852426?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzfHx8ZW58MHx8fHw%3D&w=1000&q=80" style="width:100%">
                <img class="mySlides1" src="https://media.istockphoto.com/id/1409254639/photo/autumn-drive.jpg?b=1&s=170667a&w=0&k=20&c=phQOICvfLifPWESZu3AioY7sKM9s_HQnCozMKF6g120=" style="width:100%">
                <img class="mySlides1" src="https://media.istockphoto.com/id/1427249962/photo/tropical-leaves-abstract-green-leaf-texture-in-garden-nature-background.jpg?b=1&s=170667a&w=0&k=20&c=40KcV7mbAQWihuO0At8GSOTIKp-TvIoHGIhurHBeUq0=" style="width:100%">
            </div>

            <script>
                var myIndex1 = 0;
                carousel1();
                
                function carousel1() {
                  var j;
                  var y = document.getElementsByClassName("mySlides1");
                  for (j = 0; j < y.length; j++) {
                    y[j].style.display = "none";  
                  }
                  myIndex1++;
                  if (myIndex1 > y.length) {myIndex1 = 1}    
                  y[myIndex1-1].style.display = "block";  
                  setTimeout(carousel1, 2500); // Change image every 3 seconds
                }
                </script>

        </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The content in tinymce cannot be edited or removed

Is there a method to prevent certain content within the tinyMCE Editor from being edited or removed? While I know that adding a class "mceNonEditable" can make a div non-editable, it can still be deleted. Is there a way to make it unremovable as well? ...

Tips for utilizing the verticesNeedUpdate feature in threejs for refreshing the vertex positions of a 3D cube

let geometry = new THREE.BoxGeometry(500, 500, 500); scene.add(geometry); let edgesGeometry = new THREE.EdgesGeometry(geometry); scene.add(edgesGeometry); let material = new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 }); scene.add(material); ...

Problems with script-driven dynamic player loading

I am attempting to load a dynamic player based on the browser being used, such as an ActiveX plugin for Internet Explorer using the object tag and VLC plugin for Firefox and Google Chrome using the embed tag. In order to achieve this, I have included a scr ...

Connecting Lavarel Pusher Socket in NUXT with SSR Mode

Looking to establish a connection between the Laravel Pusher Socket and NUTX.js (SSR Mode) Application. The code snippet above adds the socketio.js plugin file, but it seems to be causing some issues. Can anyone point out what might be going wrong? And ...

How to implement an OR condition using EJS?

These different options both function correctly: <% if(currentUser.collegeLevel === "High School") { %> <h1>They attained a High School Diploma</h1> <% } %> <% if(currentUser.collegeLevel === "Associates Degree") { %& ...

Stuck on changing the background color of a DIV in WooCommerce product descriptions with CSS

I seem to be stuck on a simple fix and despite searching everywhere, I can't seem to make it work. The problem lies within WooCommerce on my WordPress site, where I suspect that my CSS is conflicting with WC's and causing some color problems. Yo ...

An object in typescript has the potential to be undefined

Just starting out with Typescript and hitting a snag. Can't seem to resolve this error and struggling to find the right solution useAudio.tsx import { useEffect, useRef } from 'react'; type Options = { volume: number; playbackRate: num ...

What is the best way to use CSS in conjunction with a Master Page and a new content page, ensuring that the new CSS does not interfere with

Currently, I am working with an ASP.Net 4.5 website that incorporates a master page. The site utilizes a CSS file that is applied universally across all pages. Recently, I added a new page to the website which contains its own custom CSS specifically desig ...

Is it possible to simultaneously run two Node.js projects on Windows?

Is it possible to run two Node.js projects on a Windows operating system? If so, what is the process for doing that? If not, can I run two Node.js projects on a dedicated host instead? ...

Transforming a PHP cURL call to node.js

Currently exploring the possibility of utilizing the Smmry API, however, it seems that they only provide PHP API connection examples. Is there anyone who could assist me in adapting it into a JS request? My requirement is simple - I just need it to analyz ...

iPad is playing the incorrect file when using .play(). Any ideas on how to fix this issue?

Currently, I am developing a web application that involves a div element with dynamic text content that changes based on user interactions. To enhance the user experience, I decided to incorporate audio elements by creating an array containing correspondin ...

Error encountered while exporting TypeScript module

While I am working with Angular, TypeScript, and Gulp, my module system is CommonJS. However, I encountered an error when trying to import a module into my main.ts file: Error: Cannot find external module 'modules.ts'. Here is the snippet from ...

Failure to trigger the callback for mongoose.connection.once('open') event

Currently, I am in the process of setting up a custom Node server using Next.js. Although I'm utilizing Next.js this time around, it should not affect the outcome. In my previous applications, I always relied on mongoose.connection.once('open&ap ...

JQuery mishandles its left positioning

Here's the code snippet I've been working with: $(this).closest("p").after('<strong>' + arMess[iCurIndex] + '</strong>').next().animate({ top: $(this).offset().top - 57, left: -$(this).widt ...

Dynamic jQuery URL truncater

Is there an on-the-fly URL shortener similar to Tweetdeck available? I have come across several jQuery and JavaScript plugins that can shorten a URL through services like bit.ly when a button is clicked. However, I am looking for one that shortens URLs aut ...

Is there a way for me to set distinct values for the input box using my color picker?

I have two different input boxes with unique ids and two different color picker palettes. My goal is to allow the user to select a color from each palette and have that color display in the corresponding input box. Currently, this functionality is partiall ...

While attempting to make my div responsive, it unexpectedly became stuck to the navbar

After successfully creating a website that works fine on desktop, I encountered an issue when viewing it on my phone. The main content section, which features jokes, gets scrolled up along with the navbar. I followed a tutorial on YouTube to make the navba ...

What is the best way to display a message when a record cannot be found?

I have created a HTML PHP table page with full codes. The code is working fine, but I am facing an issue where it doesn't display anything if the record does not exist. I want to show a message when the record does not exist. <!DOCTYPE html> < ...

Instructions for triggering the opening of a colorbox within an iframe directly on top of the parent window

I am encountering an issue on a page with an iframe. When clicking on a link inside the iframe, it opens a colorbox as expected. However, the colorbox opens within the iframe itself. Is there a way to have the iframe open over the parent window instead? ...

Styling Labels with CSS Wildcard

I have been using the free NinjaForms plugin on my WordPress site. The default styling for labels is bold, but I prefer them to be lighter. Currently, I achieve this through CSS by targeting individual field IDs. However, this method becomes tedious when a ...