Unique title: "Unique Javascript Carousel Variation with Common Layout and Style"

I've been pondering over something lately, and despite searching on Google, I couldn't find a solution specific to my situation. It seems like no one has asked this exact question before.

My current dilemma is as follows: I have a section with four vertical divs (although only two are shown in the code) that I want each to trigger a different Lightbox/Carousel when clicked. Below is the code I currently have, without the CSS which only includes styling for Slides and Modal/Carousel layout.

The Issue

What I'm struggling with is how to trigger different carousels while using the same styled Modal/Carousel layout in CSS. For instance, I would like the second Slide to open a Lightbox/Carousel containing images 3.jpg and 4.jpg.

Cheers, and have a great day. Thank you in advance.

I am still a beginner, so there may be some unnecessary pieces of code that are not being used.

HTML

<section class="row" id="gallery" data-toggle="modal" data-target="#exampleModal">
 <div class="slide" alt="First slide" data-toggle="modal" data-target="#exampleModal" data-slide-to="0" >
      <div class="content">
        <h2> Pre-Wedding</h2>
        <p>Bla-bla-bla-bla</p>
      </div>
  </div>
  <div class="slide" alt="Second slide" data-toggle="modal" data-target="#exampleModal"  data-slide-to="0">
      <div class="content">
        <h2> Groom</h2>
        <p>Bla-bla-bla-bla</p>
      </div>
  </div>
</section>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
        <div class="modal-body">
          <div id="carouselExample" class="carousel slide" data-ride="carousel">

              <div class="carousel-inner">
                <div class="carousel-item active">
                  <img class="d-block " src="1.jpg" alt="First slide">
                </div>
                <div class="carousel-item">
                  <img class="d-block " src="2.jpg" alt="Second slide">
                </div>

                 ...other Images

              </div>
              <a class="carousel-control-prev" href="#carouselExample" role="button" data-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
              </a>
              <a class="carousel-control-next" href="#carouselExample" role="button" data-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
              </a>
    </div>
   </div>
  </div>
 </div>
</div>

Javascript

document.getElementById('gallery').classList.add("custom");
document.getElementById('exampleModal').classList.add("custom");

Answer №1

Discovered a new method to achieve the desired outcome. Essentially, I made alterations to the CSS code like so:

CSS

#exampleModal.custom{
...
}

Javascript


document.getElementById('gallery').classList.add("custom");
document.getElementById('exampleModal').classList.add("custom");

and modified it to look like this:

CSS

#exampleModal.custom, #carouselone.custom{
...
}

Javascript

document.getElementById('gallery').classList.add("custom");
document.getElementById('exampleModal').classList.add("custom");
document.getElementById('carouselone').classList.add("custom");

Now, by adjusting the ID and data-target, the same layout can be triggered with different content (images). While I am not certain if this is the most efficient approach, it does get the job done.

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 process for relocating a marker to a predicted address from the AutoComplete API

My attempt to achieve this is through the following lines of code: var marker = new google.maps.Marker({ position: geolocation, animation: google.maps.Animation.BOUNCE }); marker.setPosition(geolocation); The code snippet above, which ...

Adding a loading event listener to an object in JavaScript: A step-by-step guide

I'm currently deep into developing a game using sprites in JavaScript. I've been trying to incorporate an event listener that verifies whether the sprite images have loaded before beginning the game. Employing object-oriented programming, I' ...

Leverage AngularJS templates across multiple locations

I currently have a table that showcases a list of products. This table is utilized on both the "All products" page and the "My products" page. Here is a snippet of the table code: <tr ng-repeat="product in products> <td>{{product.id}}</td ...

Subdomain Dilemma: Trouble with Images in Internet Explorer

Currently, I am working on creating a basic website on a subdomain. Everything appears to be running smoothly in Google Chrome except for one issue with the header image not displaying in IE8. The image link is . It seems that the problem may stem from IE ...

Ways to instantly receive server (express) sent events from client (vue)

I am facing an issue with my Vue.js client not immediately listening to Express server sent events. Currently, the client only starts listening once the whole process is completed. This is a snippet of my Express Controller Code: exports.getFruits = (req ...

Do any iOS web browsers via CSS support OpenType font characteristics?

OpenType features are supported by the current version of desktop Chrome using CSS. 1) According to my testing, OpenType features are not supported by Safari or Chrome on iOS 5. Is this accurate? (I have confirmed that the -webkit-font-feature-settings CS ...

Receive live feedback from shell_exec command as it runs

I have been working on a PHP-scripted web page that takes the filename of a previously uploaded JFFS2 image on the server. The goal is to flash a partition with this image and display the results. Previously, I had used the following code: $tmp = shell_ex ...

Activate a key press event (keydown) using jQuery

After researching extensively and trying various approaches, I am still unable to find a solution that works for my problem. The issue at hand involves a search input field. When the user clicks on an example button, I want the word "doctor" to be written ...

Tips for chaining API calls in Angular using rxjs?

How can I efficiently nest API calls in Angular using RxJS? getProducts(): Observable<any> { return this.getProductIDs().pipe( map((response) => response.products.map((data) => (item: any) => flatMap(() => th ...

Using the jQuery attr method to assign values to newly created DOM elements generated by an AJAX request

I have a div on a webpage that undergoes changes through AJAX requests triggered by user interaction with a dropdown menu. When the page first loads, I have a script to disable autocomplete for all text input elements: //Prevent browser autocomplete funct ...

Refreshing Flask Jinja2 template table with a button press

I am utilizing a Flask app for the automated provisioning of servers on my cloud platform, and one of the features allows users to upload a spreadsheet that is then parsed into an interactive HTML table. After populating the table with data, the fields ar ...

Tips for positioning the text and icon within a tag nestled in a paragraph tag?

Need help aligning text and icons inside paragraph tags on a tag. Here is the HTML code I'm currently using: <div class="application-intro"> <p><a class="btn" href=""><i clas ...

typescript warns that an object may be potentially null

interface IRoleAddProps { roles: Array<IRole> } interface IRoleAddState { current: IRole | null } class RoleAdd extends React.Component<IRoleAddProps, IRoleAddState> { state = { current: null, } renderNoneSelect = () ...

Issue with overflow-auto not displaying scroll bar

In my layout, I have a grid parent with two columns. The left child has a height equal to the parent (100vh), while the right child is 1000px tall, which exceeds the parent's height. Here is the HTML structure: <body> <div class="le ...

What is the best way to continuously click a JavaScript link until it disappears?

Many websites utilize single-page pagination to display more content with each click. It can be beneficial to view all the content on one page, such as for web crawling purposes. Much like automatically clicking a button using Greasemonkey, how can JavaScr ...

The problem stemming from the implementation of the useNavigate() Hook in a personalized React-Admin application

I've encountered a complex issue in my React-Admin application. Whenever I attempt to utilize the useNavigate() hook within my custom login component (MyLoginPage), an error message pops up: [Route] is not a <Route> component. All component chi ...

Ways to verify login status on index.html

By using the code below in "index.php", I can determine the user's session status: <?php if(isset($_SESSION['id'])) { ?> <li><a href="controller.php?type=logout" class="btn btn-borders btn-primary">Log out</a>< ...

Tips on decorating multi-chain selection buttons

Our latest project involved implementing multi-select buttons. Due to the complexities of styling select and option tags, we decided to utilize chosen.js for this purpose. <link rel="stylesheet" href="$url_link/css/user_css/chosen.css"> <script t ...

Having trouble with changing text in a link with an onclick event?

When I click on the link, I want the text to change to the second span. However, this functionality is not working. Code var reload = false; $('#change').click(function() { reload = !reload; $('#change').click(function() { ...

Production environment does not support Meteor environment variables

I am currently deploying my app using Meteor UP and I have set the environment variables in both the mup.json file and a file called server/lib/env.js where they are stored. Here is how the variables are being accessed: Meteor.startup(function() { // ...