Is it possible to implement a single lightbox modal that can display multiple images?

I am looking to create a fullscreen lightbox modal for multiple images, but I have been facing issues with finding the right solution. Most lightbox modals out there rely on jQuery and older versions of Bootstrap.

Here is what I have tried so far:

HTML:

          <div id="howItWorksSteps">
        <p>2) Customer selects items to be included in quote.</p>
        <img class="myImg" src="images/MarketplaceSolution_3.jpeg" alt="" style="width:100%;max-width:300px"
        data-bs-target="#myModal">
        <p>3) Customer selects shipping options.</p>
        <img class="myImg" src="images/MarketplaceSolution_4.jpeg" alt="" style="width:100%;max-width:300px"
        data-bs-target="#myModal">
        <p>4) Customer requests a quote.</p>
        <img class="myImg" src="images/MarketplaceSolution_5.jpeg" alt="" style="width:100%;max-width:300px"
        data-bs-target="#myModal">
        <p>5) Seller responds to quote with confirmed prices and shipping costs of order.</p>
        <img class="myImg" src="images/MarketplaceSolution_6.jpeg" alt="" style="width:100%;max-width:300px"
        data-bs-target="#myModal">
        <p>6a) Customer pays for order.</p>
        <img class="myImg" src="images/MarketplaceSolution_7.jpeg" alt="" style="width:100%;max-width:300px"
        data-bs-target="#myModal">
        <p>6b) Seller updates order as paid.</p>
        <img class="myImg" src="images/MarketplaceSolution_8.jpeg" alt="" style="width:100%;max-width:300px;"
        data-bs-target="#myModal">
        <p>7) Seller updates customer with shipping details including tracking numbers.</p>
        <img class="myImg" src="images/MarketplaceSolution_9.jpeg" alt="" style="width:100%;max-width:300px"
          data-bs-target="#myModal">


        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="multipleModalLabel"
          aria-hidden="true">
          <div class="modal-dialog modal-fullscreen">
            <div class="modal-content">
              <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              <div class="modal-body">
                <div class="container-fluid p-0">
                </div>
              </div>
            </div>
          </div>

Javascript:

const divHowItWorks = document.getElementById("howItWorksSteps");
const howItWorksImgs = divHowItWorks.querySelectorAll("img");
howItWorksImgs.click(function() {
  const imageSrc = $(this).data('src');
});

const myModal = document.getElementById("myModal");
const currentImg = document.getElementById("image");
currentImg.attr('src', '');

Answer №1

Implement the lightbox.js script to simplify your life. The key element in your HTML is data-lightbox="photos".

Make sure to download both the lightbox.js and lightbox.css files. You can find them on this CDN link.

<div class="thumbnailContainer">

  <a href="pic01.jpg" data-lightbox="photos"> <!-- Full photo -->
    <img class="img-fluid" src="pic01small.jpg"> <!-- Thumbnail / Small Clicker -->
  </a>

  <!-- Include additional pictures here and then place this entire Div inside your modal -->

</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

Difficulty encountered when transferring an array from Xcode to JavaScript via SBJSON

In an attempt to transfer an array from Xcode to a local HTML file, I am utilizing jQuery in the HTML code. This involves using loadHTMLString: with baseURL to read both the HTML and included .js files. However, I am encountering an issue when trying to us ...

Using Vue.js to conditionally render content based on changes in a variable

I am facing a challenge in rendering a new element once the boolean variable waiting changes to true. The issue arises when transitioning from one v-if statement to another, as the boolean does not update until the first statement is completed. How can I s ...

Is there a way to turn off predictive text for reCAPTCHA on my mobile device?

Using reCAPTCHA on a sign-up form can get frustrating on mobile devices, with constant dictionary word suggestions while typing. I am aware of how to disable this feature for normal input fields by adding attributes through JavaScript, but shouldn't ...

react validation for dropdown, react-datepicker, and hour input at intermittent intervals

I have integrated the following packages into my project :- react-datepicker library for selecting from time and to time date validation with date-fns, moment.js, additional validations using jQuery and lodash libraries/packages If you want to view my pr ...

Troubleshooting the Hover Effect of Buttons in Next.js when Using Tailwind CSS for Dynamic Color Changes

Encountering a problem with button hover functionality in a Next.js component using Tailwind CSS. The objective is to alter the button's background color dynamically on hover based on a color value stored in the component's state. This code func ...

The error message "Uncaught ReferenceError: req is not defined with [email protected]" indicates that the variable

Discovered a helpful post that seems to address the problems. https://github.com/angular/angular-cli/issues/8359 I'm unsure about the steps to take next to resolve this issue. Can anyone clarify? Could you please advise on which version of Angular ...

What techniques do platforms like Twitch, YouTube, Twitter, and Reddit use to dynamically load pages and update the URL without triggering a full reload?

Have you ever noticed that on some websites, when you click a link the page goes blank for a second and shows a loading indicator in your browser tab? However, on platforms like YouTube and Twitch, clicking a link smoothly transitions to the new page wit ...

In the process of making a request with axios in an express server

Struggling with a simple call to an API using Axios with Express, and I can't figure out why it's always pending in the browser. Here is my route: var express = require("express"); var router = express.Router(); const controller = require("../. ...

Inject Angular 2 component into designated space

I am working on a website that requires a settings dialog to be loaded in a designated area upon clicking a button. The settings dialog is a component that retrieves data from REST endpoints. I am hesitant to simply insert the component and hide it as I ...

Utilize Nuxt.js context within a Vue plugin

I have a situation where I'm working with Nuxt.js and have two plugins set up. In order to gain access to the VueI18n instance from lang.js within validate.js, I am in need of some guidance. Is there anyone familiar with how this can be accomplished? ...

unable to connect a value with the radio button

I am struggling to incorporate a radio group within a list of items. I am facing difficulty in setting the radio button as checked based on the value provided. Can anyone provide me with some guidance? Here is the HTML code snippet: <div *ngFor=" ...

Cross-Domain Communication with XMLHttpRequest

I am facing an issue with the code snippet below: console.log(1); var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://anothersite.com/deal-with-data.php'); xhr.setRequestHeader('Content-typ ...

How to use puppeteer to extract images from HTML that have alt attributes

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 nopadding text-center"><!-- Start Product Photo --><div class="row"><img src="/products/ca/downloads/images/54631.jpg" alt="Product image 1">&l ...

The reactivity of VUE 3 arrays is not being updated, but individual array elements accessed using array

Currently facing an issue while trying to connect a dynamically updating array of objects to a Konva circle. The circles are appearing as expected, but the problem arises within a for loop where I update player locations based on a "tick". While setting th ...

The iFrame's getFocus function does not activate

I have an iframe set up like this: <iframe name="richTextField" id="richTextField" style="border:#000 1px solid; width:700px; height:300px;"></iframe> I also have some JavaScript code that is supposed to trigger when the iframe gains or loses ...

Shift all content to the right when viewing on mobile devices

I'm looking to create space for a menu on the left side, similar to the one on Mashable's mobile view. How can I move all the content to the right? Feel free to resize the window and compare with . Thank you. Best regards, Marius ...

What is the best practice for adding a DOM element at a precise location within an ng-repeat loop?

I am currently working on developing a podcast player application using AngularJS. At this point, I have successfully created a list of available podcasts that can be played, utilizing ng-repeat. The code for the list is shown below: <ul ng-controller ...

Is it possible to load Angular.js without any references?

In the process of reverse engineering a User Interface that is operational but has a few bugs. Created using HTML, CSS, and JavaScript with data acquired through a REST API. The interface is designed for a Windows environment. While examining the index.ht ...

Updating the database with values dynamically using ajax without the need to refresh or change the current page

My current challenge involves adding records to a database table without the need to reload the page. I've implemented ajax for this purpose, but have been receiving an unexpected response (201) from the server (alert("Error occurred !")). Despite spe ...

The error message "SharedArrayBuffer is not defined" occurred when attempting to utilize ffmpeg.wasm

<!DOCTYPE html> <html> <head> <title>TikTok Live Downloader</title> </head> <body> <h1>TikTok Live Downloader</h1> <label for="username">Username:</label> ...