Numerous sleek carousels showcased in modal overlays, all running simultaneously

Having a page with multiple hidden Slick carousels, I want the user to click a specific button to launch the corresponding slider in a modal with a semi-transparent background.

The issue is that when you launch any carousel on the page, all carousels start autoplaying behind each other.

Below is my HTML structure:

<button class="launch-gallery">Launch gallery 1</button>
<div class="modal">
  <div class="img-gallery">
  <h2>Gallery 1</h2>
  <div class="img-gallery__slides">
    <div class="img-gallery__slide">
      <img src="image-1.jpg" alt="" />
    </div>
    <div class="img-gallery__slide">
      <img src="image-2.jpg" alt="" />
    </div>
  </div>
</div>

<button class="launch-gallery">Launch gallery 2</button>
<div class="modal">
  <div class="img-gallery">
  <h2>Gallery 2</h2>
  <div class="img-gallery__slides">
    <div class="img-gallery__slide">
      <img src="image-3.jpg" alt="" />
    </div>
    <div class="img-gallery__slide">
      <img src="image-4.jpg" alt="" />
    </div>
  </div>
</div>

And here is the JavaScript code to trigger the modal:

var $galleryModal = $('.modal');

$('.launch-gallery').click(function(){

    $galleryModal.toggleClass('is-open');

    return false;
});

As for the Slick configuration, it looks like this:

var $imgGallery = $('.img-gallery__slides');

$imgGallery.slick({
  infinite: true,
  slidesToShow: 1,
  slidesToScroll: 1,
  dots: false,
  arrows: false,
  accessibility: false,
  cssEase: 'ease',
  autoplay: true,
  autoplaySpeed: 5000,
});

The question remains - Is there a way to only launch the carousel related to the button clicked?

Answer №1

You can attempt a solution in this manner

$('.open-gallery').click(function(){

$(this).next('.popup').toggleClass('visible');

return false;
});

Answer №2

Here are some steps to try:

let $modalBox = $('.modal');

$('.launch-gallery').click(function(){

    $modalBox.next('.modal').toggleClass('is-open');//toggle open the modal associated with the button
    let $imageGallery = $(this).next('.modal').find('.img-gallery__slides');//get the gallery from that particular modal
$('.img-gallery__slides').slick('unslick');//destroy any other existing gallery 
$imageGallery.slick({
  infinite: true,
  slidesToShow: 1,
  slidesToScroll: 1,
  dots: false,
  arrows: false,
  accessibility: false,
  cssEase: 'ease',
  autoplay: true,
  autoplaySpeed: 5000,
});
    return false;
});

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 most effective method for a JavaScript function to perform a basic AJAX true/false query and provide the outcome?

How can a JavaScript function be used to perform a basic AJAX request that returns a true/false result? I am looking to create a JavaScript function that makes an AJAX request to check if a user's session is still active. The function should wait for ...

Retrieve information from an XML document by utilizing the $.ajax method

Hey everyone, I'm new to jQuery and I'm working on creating an Ajax function to fetch data from an XML file to display in my HTML file. Below is my code: HTML <div id="myDiv"></div> <button>Get info</button> UPDATED XML ...

How can we consolidate the data gathered from mongodb - through aggregation, map reduce, or alternative methods?

I'm currently struggling with aggregation problems. I initially considered using map reduce or separate find queries combined with the async library to tackle the issue. Here is the schema for reference: db.keyword keyword: String start: Date sour ...

As the Div descends, it endeavors to maintain alignment with its counterparts

My webpage has a parent div with multiple child divs in one row. These child divs are generated dynamically, so I don't know how many will be displayed at once. The parent div has a fixed width and a horizontal scrollbar appears when all child divs ar ...

Vue unable to load material icons

The icons npm package "material-icons" version "^0.3.1" has been successfully installed. "material-icons": "^0.3.1" The icons have been imported as shown below. <style lang="sass"> $material-icons-font-path: '~material-icons/iconfont/'; ...

Applying a background image to Django templates: Step-by-step guide

I am encountering an issue on my website where I need to insert an image as a background in a specific table cell. However, the image appears duplicated because it is smaller than the cell's width and height, causing an overlap effect. Even though I ...

Display the AJAX loading indicator with a slight delay rather than instantly

For my latest web app project, I have incorporated numerous ajax calls. While the majority of these calls are quick and provide immediate responses, I am interested in implementing an ajax loader to display when calls take longer than 250ms. This will pr ...

Backbone.js struggles with rendering collection object fields when the JSON response is enclosed within a "book" domain wrapper

Upon receiving the following JSON data, the view and HTML code successfully renders the values on the webpage. JSON DATA [{"id":"1234","name":"book1","type":"catg1"},{"id":"1235","name":"book2","type":"catg1"}, {"id":"1236","name":"book3","type": ...

Restrict HTML Elements Based on Their Size

I have a text file with a substantial amount of content that I need to display in an HTML format. The challenge is that I only want to show a portion of the text on the screen, but I am unsure of the exact amount that needs to be displayed. What I do know ...

Exploring how to incorporate Express middleware into Firebase Functions for handling HTTPS requests

Encountering a challenge while using Express middleware with Firebase Functions. In this sample, a function is linked to the app() instance as shown below: app.get('*', (req, res) => { res.send(`Hello ${req.user.name}`); }); exports.autho ...

Using eslint for pre-commit hooks in Git

Is there a way to run eslint on files in the pre-commit script when they are in the add stage? I've placed the .eslintrc file in the hooks folder. Additionally, I have the following script: #!/bin/sh # # An example hook script to verify what is abo ...

Obtaining the sum of two variables from two separate functions results in a value of NaN

Why is it that I'm seeing a NaN result when trying to access a variable in two different functions? This is my code var n_standard = 0; var n_quad = 0; var totalQuad; var totalStandard; var total = totalStandard + totalQuad; ...

Is the Angular Library tslib peer dependency necessary for library publication?

I have developed a library that does not directly import anything from tslib. Check out the library here Do we really need to maintain this peer dependency? If not, how can we remove it when generating the library build? I have also posted this question ...

Vue: Develop a master component capable of displaying a sub-component

Is there a way to design a main component that is able to accept and display a subcomponent? Take the following scenario for instance: <Container> <Item/> <Item/> <SubMenu/> <Btn/> </Container> ...

"What is the best way to switch between multiple data targets and toggles in bootstrap using the HTML data toggle attribute

I am currently coding an animated hamburger icon for the Bootstrap navbar, and I need to find a way to toggle both the hamburger icon and the responsive navbar. Is there a method or code snippet that allows me to toggle these two elements independently usi ...

In PHP, you can use the `echo` statement to output an HTML input

Incorporating HTML into PHP using heredoc methodology can sometimes lead to challenges when trying to retrieve user input variables. Attempting to access the input variable with $_GET["input"] may result in an error message indicating an undefined index: ...

One simple trick for aligning checkboxes with their corresponding tags in a single line

Have you encountered issues with a CheckBoxList displaying text in one line below its checkbox when the ListItem has many words? Some checkboxes may also have smaller characters than usual. If you have any solutions or ideas, please share them as I would ...

Heroku: Encounter Error 414 (Request-URI Exceeds Length Limit)

EXPECTED OUTCOME: The Post request is successfully completed, saving the poll in the database. CURRENT SITUATION: While my SPA functions properly on my local machine, I encounter a 414 error when attempting to create a Poll after uploading it to Heroku. ...

"Exploring the Power of Node.js and Firebase for

I'm encountering some issues with Node.js, as I am fairly new to it. I am attempting to create a post method, but it keeps returning Something is not right and I'm struggling to identify the problem Here is the code snippet. exports.createN ...

Glitches in the fluid design of ie7

After creating a prototype layout for my latest design, I noticed that resizing the window in ie7 causes the content area to drop below the sidebar. This issue doesn't occur in other browsers, including ie6. Check out the demo here I need help ident ...