Are image collections featuring the <img> tag available?

I am working on a website project and I'm looking for a way to create a gallery with a group of photos. The challenge is that I am using Spring MVC, which means regular js and jquery plugins may not work with my 'img src..' tags. Are there any specific plugins or libraries that are compatible with this setup? If not, I would appreciate any suggestions or alternative solutions. Here is the html code for reference:

<div id="img-slider">

                <img class="slider-img" src="/LBProperties/img/bisc.jpg"/>
                <img class="slider-img" src="/LBProperties/img/bisc1.jpg"/>

</div>

Any help would be greatly appreciated! Thank you!

Answer №1

To achieve the effect of hiding all images with CSS, use the following code:

img {
  width: 100px;
  height: 100px;
  display: none;
}

Access the image elements using handlers:

var slider = document.querySelector('#img-slider');
var images = slider.getElementsByTagName('img');

Initialize the index variable to 0:

var index = 0;

Show the first image by setting its "display" property to 'block':

images[index].style.display = 'block';

Include a button in your HTML structure:

<div>
<button id="next">Next</button>
</div>

Retrieve the button element using script and attach a click event handler to it:

var button = document.querySelector('#next');

button.addEventListener('click', function() {
  for (var ix = 0; ix < images.length; ix++) {
    images[ix].style.display = 'none';
  }

  index++;
  if (index >= images.length) index = 0;
  images[index].style.display = 'block';
});

The click event handler cycles through the images, hides them, increments the index value, ensures that the index does not exceed the number of images (resetting it to 0 if necessary), and then displays the next image.

Here is the link to see all the code put together: https://jsfiddle.net/subterrane/osszqoLe/

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

Sending information from an AngularJS selected item to an edit form

Currently, I am working on an add/edit form using angularJS. Within this project, there are two templates - one for displaying a list of items and another for the form itself. While adding new items works smoothly, I have encountered some challenges when i ...

Adjust the color of the text in the Stepper component using React Material UI

Is there a way to modify the text color within the stepper? Specifically, I aim to have the number 3 displayed in black instead of white: Image Link ...

Automatically Refresh a Div Element Every 5 Seconds Using jQuery's setInterval() Function

My goal is to refresh the left div every 5 seconds using $.ajax to get JSON data and display 4 random elements in that div. However, even though the left div block refreshes, the content remains the same with the same images always showing. view image desc ...

Activate trust proxy in Next.js

When working with Express.js, the following code snippet enables trust in proxies: // see https://expressjs.com/en/guide/behind-proxies.html app.set('trust proxy', 1); I am attempting to implement a ratelimit using an Express middleware that is ...

Submit Button Not Responding on Mobile Device

I am facing an issue with my VueJs app. The contact form works perfectly on browsers, but when accessed from a smartphone or tablet, it fails to function properly. I have tried two different implementations to resolve the problem. Here is the first implem ...

IE11 is throwing an error due to an unexpected quantifier in the regular expression

I have a string like SHM{GHT} and I need to extract the value from within the curly braces (GHT in this case). I used RegExp successfully to do this, but encountered an issue when testing on Internet Explorer. The page broke and I received an error message ...

Utilizing JavaScript for validation on an ASPX page within Visual Studio

After entering an email ID in a textbox, the email validation process is initiated. However, it seems that there is an issue where the entire function may not be executed properly. <head runat="server"> <title></title> ...

Prevent Float Filtering in AngularJS

As I work on creating a directive in AngularJs, I am facing an issue. The directive is supposed to receive a JSON object from the app controller and display its content accordingly. To better illustrate my problem, I have created a simple demo which can b ...

Managing large datasets effectively in NestJS using fast-csv

Currently leveraging NestJS v9, fast-csv v4, and BigQuery for my project. Controller (CSV Upload): @Post('upload') @ApiOperation({ description: 'Upload CSV File' }) @ApiConsumes('multipart/form-data') ... // Code shorten ...

Validate the Vuetify data table by retrieving data with a fetch request

I have integrated a v-data-table into my project to display data pulled from the backend. The data comes in the form of item IDs. How can I efficiently match the incoming IDs with the object IDs in the categories and show the corresponding category names i ...

AngularJS: iterating through POST requests and passing each index into its corresponding response

Using AngularJS, I am attempting to execute multiple http POST requests and create an object of successfully finished requests. Here is a sample code snippet: var params = [1, 2, 3], url, i, done = {}; for (i in params) { url = '/dir ...

Tips for retrieving multiple values or an array from an AJAX request?

Is there a correct way to pass multiple sets (strings) of data back after executing an ajax call in php? I understand that echo is typically used to send a single string of data back, but what if I need to send multiple strings? And how should I handle th ...

Bootstrap table exceeds the boundaries of the smartphone screen

I'm currently working on my first laravel project with bootstrap (https://getbootstrap.com/) and I've encountered an issue related to mobile device responsiveness. The problem arises when using a basic table in bootstrap4 (the absence of the res ...

Real-time data updates not working in jQuery data table

I am currently dealing with a data table and using ajax to fetch data for display on my HTML DOM page. However, I have encountered an issue after implementing server-side processing for the data table. Even though I can successfully retrieve records in my ...

Tips for ensuring all data is downloaded in Firebase (Firestore) Storage before proceeding?

I am currently developing a light dashboard in Vue that connects to Firestore and Storage. As someone who is not an expert, I have encountered a roadblock in what should be a simple task. The issue lies with a function that is meant to retrieve all URLs ba ...

Is it possible to trigger a server-side event using jQuery in SharePoint 2010?

For my Sharepoint 2010 application, I have been utilizing jQuery to handle most events on the client-side. However, when it comes to saving data to the Sharepoint list and generating a PDF file with that data, I need to switch to server-side processing usi ...

Tips on halting the current animation and modifying styles upon hovering

Currently, I have a basic label featuring a contact number with a blinking animation. However, the animation is only a simple color transition at this time (see code below). I have managed to successfully pause the animation and revert the text back to it ...

Tips for choosing an item in a multi-select dropdown using Selenium WebDriver

Currently delving into Selenium WebDriver while utilizing Java.. I am curious about how to select values in a Multi-select box where the options are already pre-selected. If I want to choose two or more additional options, how can I go about it? The HTML ...

Why do static files in Node.js + Express.js on Windows take up to two minutes to load?

I'm encountering an issue in my Windows environment with Node.Js/Express.js where static JS files can sometimes be labeled as 'pending' in the browser (even with caching disabled) for up to two minutes before finally downloading successfully ...

While executing a for loop, the variable $.ajax is found to be null in Javascript

When I click on a button with the function btn-book, there is a for loop inside it that fetches data from Ajax. Despite knowing that the data holds values, I constantly receive null. Below is the code snippet for the onclick event: $('#mapContainer&a ...