Steps to gather all the images within a directory

Take a look at this demo

When you click on the "next" button, new images are loaded from the internet.

In my application, all the images are stored in the img/image folder with names like 1.jpg, hi.png, etc.

My question is, how can I display these images when the "next" button is clicked?

I am considering modifying the line

var srcs = [ 'http://lorempixel.com/150/100/city', 'http://lorempixel.com/150/100/sports' ];
to
var srcs = [ 'img/image/1.jpg', 'img/image/hi.png' ];

However, if I do it this way, I will need to manually update the var srcs array every time a new image is added to the folder.

For example, if I add 3.jpg at a later time, I would have to edit

var srcs = [ 'img/image/1.jpg', 'img/image/hi.png','img/image/3.jpg' ];
manually.

Answer №1

Check out this example that might be helpful, although it may not be the most efficient solution http://jsfiddle.net/PrVRq/:

$('.images').on('loaded', function () {// load an image}

Attempt to load the next image

img.load(function () {    
    $('.images').append(img);
    $('.images').trigger('loaded');
});

If the image is successfully loaded, trigger the 'loaded' event to load another one.

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

Leveraging AJAX to call upon a designated php file

I have a selection of menu items on my webpage, each with different options: option1, option2, and option3. Additionally, I have corresponding PHP files on my server for each of these menu items: option1.php, option2.php, and option3.php. For simplicity, ...

JavaScript - exploring techniques to alter the relationship between parents and children

I'm facing an issue with transforming the parent-child relationship in my data structure. Currently, it looks like this: { "id": 7, "name": "Folder 1", "parent_folder": null, "folders": ...

What is the best way to simultaneously send JavaScript variable and form data in Django?

I am trying to send a JavaScript variable to a Django view using the ajax() method. Below is my code: $('#orderDetails').submit(function() { // catch the form's submit event $.ajax({ type: 'POST', ...

What is the method for creating a JavaScript array that closely resembles the provided example?

My task is to create an addRows method using specific data structure as shown below. data.addRows([ ['UK', 10700,100], ['USA', -15400,1] ]); However, the data I have available is in a different format. How can I transform ...

Why using $refs in interpolation fails and leads to errors in Vue.js 2.x components

Here is a codepen I created: codepen const sidebar = { name: "sidebar", template: "<p>SIDEBAR</p>", data() { return { active: true }; }, methods: { test() { alert("test: " + this.active) } } }; new Vue ...

Tips on adding a hotspot to an image using jQuery for selecting a specific area

I am looking to divide an image into multiple sections. When hovering over each section, I want a tag to be displayed. This should also work smoothly with responsive design. Can anyone assist me with this? Thanks! ...

Implementing numerous dropdown input features within a single webpage

I am facing an issue while trying to pass a URL with parameters through a dropdown select input by calling a function using the onchange event. The problem arises when there are multiple dropdowns on the same page, each triggering the same function. Even ...

What is the best way to set a specific maximum size for the dropdown selector in Material UI's TextField component?

Working on a Sign up Page involves prompting users to select their location from a dropdown list of different countries. However, the issue arises when the dropdown list covers the entire screen, making it difficult for users to navigate. Is there a way to ...

Having trouble loading styles in Vue after publishing to npm

I'm currently using vue-cli3 for the npm publication of a Vue component. Below are my build scripts: "package-build": "eclint fix && vue-cli-service build --target lib --name @xchat-component/chat-component ./src/index.ts & ...

Rails triggers the "ajax:success" event multiple times

I'm working on a project to display user's following and follower list similar to Instagram: This is my controller: def create @relationship = current_user.active_relationships.new followed_id: @user.id if @relationship.save byebu ...

Sending an array encoded in JSON to jQuery

I'm attempting to send an array that I've created in PHP using json_encode(). The process involves running an AJAX request, as shown below: AJAX CALL: $.ajax({ type: "POST", url: "../includes/ajax.php?imagemeta=1", data: ...

How can the value of a button be displayed in an input box using an onclick function?

When the button '1' is clicked, it displays the value "1" inside a <!p> tag. However, the second button '2' does not display the value "2" in the input box. Even though both functions are identical. //Function with working func ...

Issues with Implementing Custom CSS Styles in ag-grid

It seems like a simple customization, but the documentation on it is quite limited. I'm trying to change the line-height of one of my tables so that text doesn't double-space when wrapping. Here's the CSS code from Test.module.css: .ag-them ...

Massive React State Array containing hundreds of Input elements, sluggish state updates triggered by onChange events

I am working on a React form that consists of multiple complex inputs, each with its own complex state. To manage the state of all these inputs, I have a parent component where each input is wrapped in a child component. The parent component holds a state ...

"Efficiently sharing information in a multi-tenant application: strategies for seamless data transfer between front

In my development of a multi tenancy application using Node.js/Mongoose and React, I made the decision to utilize a single database for all users. The main collection, dubbed companies, serves as storage for basic company data and includes a unique compan ...

Basic calculation of movement yields inaccurate outcome

I am encountering an issue with this specific function implementation. Calculations.add(this, //CONTEXT function () { //CALUCATE this.position.x += (this.movementSpeed.x / 10); }, function () { //HAVE CALCULATED ...

Is it possible to deactivate the onclick event following a successful ajax request?

I am looking to disable the onclick event after a successful ajax request. <div class="report_button" id="report_button" title="Reportthis" style="width:65px;height:15px;" onclick="reported_text(user_id,lead_id);">Report</div> This is the div ...

Putting an <input/> element inside a Material UI's <TextField/> component in ReactJS - a beginner's guide

I am attempting to style <TextField/> (http://www.material-ui.com/#/components/text-field) to resemble an <input/>. Here is what I have tried: <TextField hintText='Enter username' > <input className="form-control ...

Mongoose - facing issues with $and operator, looking for a way to locate an array containing both items

I'm currently developing a chat-based application that involves private messaging between individuals. Essentially, a Chat model in my application consists of the following schema: let schema = new Schema({ members: [{ type: ObjectId, ref: models.u ...

Remove a row from a Jquery Jtable

I am running into difficulties when trying to delete rows, and I suspect that the issue might be related to the post[id] not being properly sent. Although the delete message appears, the row is not actually deleted. Below is the snippet of my code: JAVASC ...