How can I implement two sliders on a single page using the same class?

How can I display two sliders with 3 images each at the same time without changing their classes?

<div class="abelhabil-sildeshow">
  <div class="slide">
    <img src="http://localhost/wp-content/uploads/2023/01/img_lights_wide.jpg">
  </div>
  <div class="slide">
    <img src="http://localhost/wp-content/uploads/2023/01/img_snow_wide.jpg">
  </div>
  <div class="slide">
    <img src="http://localhost/wp-content/uploads/2023/01/img_nature_wide.jpg">
  </div>
</div>
<div class="abelhabil-sildeshow">
  <div class="slide">
    <img src="http://localhost/wp-content/uploads/2023/01/img_lights_wide.jpg">
  </div>
  <div class="slide">
    <img src="http://localhost/wp-content/uploads/2023/01/img_snow_wide.jpg">
  </div>
  <div class="slide">
    <img src="http://localhost/wp-content/uploads/2023/01/img_nature_wide.jpg">
  </div>
</div>
<script>
let slideIndex = 0;
showSlides();
function showSlides() {
  let i;
  let slides = document.querySelectorAll(".slide");
  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, 1000);
}
</script>

Answer №1

Is something similar to this okay?

function eventedSlider_(){
  
    document.querySelectorAll('.slide_container:not(.evented)')
    .forEach(function(container_){

        container_.classList.add('evented');
        let items_ = container_.querySelectorAll('.slide_item');
        if( items_.length ){
            let i = 0;
            setInterval(function(){
                items_.forEach(function(item_){ item_.classList.remove('active'); });
                items_[i].classList.add('active');
                i = i+1 < items_.length ? i+1 : 0;
            },1000);
        }
    });

}
eventedSlider_();
.slide_item{
  width:20px;
  height:20px;
  margin:4px;
  background:gray;
}
.slide_item:not(.active){
  display:none;
}
<div class="slide_container">
  <div class="slide_item">a</div>
  <div class="slide_item">b</div>
  <div class="slide_item">c</div>
</div>
<hr />
<div class="slide_container">
  <div class="slide_item">d</div>
  <div class="slide_item">e</div>
  <div class="slide_item">f</div>
</div>
<hr />
<div class="slide_container">
  <div class="slide_item">g</div>
  <div class="slide_item">h</div>
  <div class="slide_item">i</div>
  <div class="slide_item">j</div>
  <div class="slide_item">k</div>
</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

What is the best way to incorporate a generated ID into the datepicker() function whenever a button is clicked?

I'm looking to dynamically generate a row of input fields with unique IDs every time the "add another flight" button is clicked, similar to the functionality seen on destina.us. Additionally, I need to incorporate these generated IDs into the jQuery U ...

Tips for enlarging an image within a 6 column class size

I'm having trouble making my image stretch to the full width, all the way to the right corner while still being responsive. The code is integrated into WordPress and you can find the image in the class membershipImgBox. How can I increase the size of ...

Simultaneous malfunction of two ajax forms

I have a dilemma with two boxes: one is called "min amount" and the other is called "max amount." Currently, if I input 100 in the max amount box, it will display products that are priced at less than $100. However, when I input an amount like $50 in the m ...

Create an instance of an object containing arrays as properties

Is there a way to initialize an object in JavaScript with properties that are arrays? I am looking to create an object structured like this: foo = { prop1: [0, 1], prop2: [1, 1], prop3: [0] } My scenario is as follows: - If a property doesn't exist ...

Tips for attaching a callback to Angular UI Popover's trigger

I recently implemented an Angular UI Popover in the following manner: <div popover-is-open="prfList.isProfileClosed===false" popover-trigger="'outsideClick'" popover-append-to-body="true" popover-placement="right-top" popover-class="popover1 ...

Ensure that the footer remains at the bottom of the page without being fixed to the bottom

I am currently working on configuring the footer placement on pages of my website that contain the main body content class ".interior-health-main". My goal is to have a sticky footer positioned at the very bottom of these pages in order to eliminate any wh ...

What is the best way to retrieve a list of unchecked checkboxes in a Razor Page model?

Currently, I am working on a razor page using .NET Core 7. I have encountered an issue where I am unable to pass values of 1, 2, and 3 for unchecked checkboxes from the HTML page to the page model in the post method. When the user clicks the submit button ...

Setting up JSP on a J2EE server using Eclipse

I'm encountering a specific issue with my setup. I am attempting to run JSP on a J2EE preview server within a Dynamic Web Project in Eclipse. While I know that it is possible to make it work by converting to a Maven project, adding dependencies, or us ...

Is it possible to use both parameters and callback functions in the MongoDB update() function in tandem?

I am looking to create a custom callback function that will check the success of the update() process and return a Q promise based on the outcome. var myCustomFunction = function (name, email) { var deferred = Q.defer(); MongoClient.connect(mongodbU ...

What options are available for labels in Bootstrap v5.0.0-beta1 compared to BS 3/4?

How can I use labels in Bootstrap v5.0.0-beta1? In Bootstrap 3, the labels are implemented like this: <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" /> <span class="label label-success ...

Extract the body.req object within a loop in a Node.js application

I'm looking to efficiently parse and save the body of a POST request using Mongoose in Node.js. Is there a way to use a for loop to accomplish this task, rather than manually saving every property? My ideal solution would involve something like: for ...

Is your server failing to respond to requests once there are too many within a session?

A web application I developed uses frequent $.ajax() calls to send and receive data between a virtual machine host and client. However, I have encountered a recurring issue where the connection cuts out after a certain number of consecutive calls within a ...

Tips for dynamically adding a style property to an element with ng-class in AngularJS

How can I dynamically change the color of a CSS class after using ng-class and add a property to an existing CSS class? <style> customcss:after{ border-top: 7px solid green; } </style> I want to be able to change the color dynamically using ...

Issue with Jquery UI Slider not correctly displaying percentages

Currently experimenting with Jquery UI sliders and things have been going smoothly so far. I am attempting to show updating percentages next to the slider while keeping all sliders linked together. I have tried a few different methods, but with mixed res ...

Track the movement of the mouse to illuminate objects in a three.js environment

Recently delving into the realm of three.js, I am seeking to achieve a solution reminiscent of this older thread with a slight tweak. The objective is to have a stationary sphere at the center of the scene while having the point light in the scene track t ...

Conceal the loading spinner in JQuery once the image has finished loading

I am working with a jQuery function that captures the URL of an image link and displays the image. However, my issue lies in managing the loading process. I would like to display a LOADING message and hide it once the image has fully loaded, but I am strug ...

Updating parent components through child components in ReactWould you like another unique

In my current project, I am attempting to change the state of the main component labeled App.tsx by using a child component called RemarksView.tsx. I have attempted passing props such as setRemarks and remarks, but unfortunately the state in the parent c ...

Launch pop-up window when the button is pressed

After successfully configuring the modal windows using Bootstrap and JQuery code along with certain values, a common query arises. The main question revolves around how to trigger the opening of this modal window upon pressing the process button? <butt ...

Check to see if a value is present in JavaScript and proceed with submitting the form

I have a situation where I am trying to capture the browser location and post it to another page. The problem I'm facing is that JavaScript takes some time to retrieve the browser location, causing the form to be submitted before the location is obtai ...

Is there a way to extract the timestamp in JavaScript from a string that includes the name of the timezone database?

Given the string: "2022/05/01 03:10:00", I am seeking to create a Date object with Chile's UTC offset. The challenge lies in the fact that due to Daylight saving time (DST), the offset changes twice annually. How can I obtain that Date obj ...