What is the best way to display images one by one from a map using a random fade effect?

I am in the process of creating a logo wall for a website. I successfully managed to display them randomly using a map, but now I want to make them appear one by one in a random order (for example: image 1, image 6, image 3, ...) and keep them visible once they have appeared.

My current approach involves setting their opacity to 0 and then changing it to 1, but I'm struggling to implement this in a random manner.

Any suggestions or help would be greatly appreciated.

EDIT:

Below is the code snippet I am working with:

import React from "react"

const logoImages = [
   // List of logo images
];

function shuffleMap(array) {
   // Shuffle array elements
}

const Image = ({ image, src }) => {
   return (
      <div className='box'>
         <div className='content'>
            <img src={image} alt={src}/>
         </div>

         {/* CSS Styles */}
         <style jsx>{`
            .box {
               min-width: 150px;
               height: 200px;
               overflow: hidden;
               display: flex;
               align-items: center;
               background: #000;
            }

            img {
               width: 120px;
               filter: grayscale(1) invert(100%);
            }
         `}</style>
      </div>
   )
}

const allImages = shuffleMap(logoImages.map((companies, index) => {
   return <Image key={companies.src + index} {...companies}/>
}));

const LogoWall = () => {
   return (
      <div className='container'>
         {
            allImages
         }
         {/* CSS Styles */}
         <style>{`
            .container {
               width: 100vw;
               height: auto;
               display: flex;
               justify-content: space-evenly;
               align-content: space-around;
               flex-flow: row wrap;
            }
         `}</style>
      </div>
   )
};
export default LogoWall

Answer №1

Have you considered adding a delay between image displays?

  1. All images are initially black due to opacity set at 0 and are randomly stacked
  2. The first image is shown immediately as 0 * 1000 equals 0 seconds
  3. Subsequent images will be displayed one by one with a 1-second interval

Here's the code snippet:

logoImages.forEach((image, index) => {
  setTimeout(() => {
    image.style.opacity = 1;
  }, index * 1000);
});

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

Modify the JSON structure of a deeply nested object

I am attempting to convert a deeply nested JSON object from one structure to another so that it can be properly used with the jQuery Nestable library. Here is the original format I am working with: { "scanned": { "a3": { ...

Send form using AJAX with a callback function

I need help figuring out how to submit a form when a captcha is clicked. I attempted to use my own jQuery function, but unfortunately it's not working. Could someone please take a look at my code and let me know what's wrong with it? Javascript ...

What is the method for accessing route parameters in class components in React Native?

Currently, I am dealing with an older React Native application and the concept of class based components is new to me. I have a boolean value (isJobOwner) that I need to pass from one screen to another. On the subsequent screen, I want to check whether the ...

Vue3 is struggling to apply dynamic styling exclusively to certain buttons

Currently, I am diving into the world of vue and facing a challenge in styling buttons dynamically when clicked individually. These buttons serve as filters for a list of products, and my goal is to apply one style when the filter is 'on' and ano ...

Encountering excessive re-renders while using MUI and styled components

Hey there! I recently worked on a project where I used MUI (Material-UI) and styled-components to render a webpage. To ensure responsiveness, I made use of the useTheme and useMediaQuery hooks in my web application. My goal was to adjust the font size for ...

Enhancing User Interfaces with React and CSS Styling

I need to incorporate two unique React components on my webpage: Component1 and Component2. Code for Page1: <Component1/> <Component2/> While the individual components will have their own CSS files for styling, I also have a page1.css file f ...

Alter the hyperlink to a different value based on a specific condition

I need help with implementing a login feature on my app. The idea is that when the user clicks the login button, it should trigger a fetch request to log in with their credentials. If the login is successful, the button's value should change to redire ...

Footer to display exclusively on the final printed page's bottom

I am facing an issue with my certificate template. It contains dynamic content in the header, body, and footer sections. When printing a single page, everything looks fine. However, when printing multiple pages, the footer does not display at the bottom of ...

The HTML background color is refusing to change

I've been struggling to tweak the background color of a specific page. I attempted setting the HTML as the background color, using !important, but unfortunately, it didn't yield the desired result. The same goes for trying to set the background c ...

Obtain a duo of distinct states with the implementation of React.useState() function

Establishing initial state: const [token, setToken] = React.useState(""); Updating the state: const calculate = () => { setToken(() =>(`name:${uuid()}`)); //_______________________________________P console.log('in calculat ...

How can I send back multiple error messages from a pug template in a node.js application with Express?

I am currently working on validating inputs from a form on a Node.js web server using Pug.js and Express.js. The issue I am facing is that when there are multiple problems with the user's input, only the first error is displayed to the user. How can I ...

Refreshing local JSON data in Vue.js

Being fairly new to Vue.js, I encountered an issue where I am unable to update or write data in my local JSON file. Let's assume that I have a data.json file https://i.sstatic.net/GZKh5.png and I want to add a new entry to it. I am currently using ...

How can a component be dynamically rendered in React?

I'm interested in exploring alternative approaches to accomplishing the same task. My desired outcome is as follows: Menu Item 1 Menu Item 2 Menu Item 3 Target (Where component should be displayed) When a menu item is clicked, I want the associate ...

An addition operation in Javascript

Recently, I dipped my toes into the world of Javascript. However, I found myself puzzled by the script and its corresponding HTML output provided below. Script: <h1>JavaScript Variables</h1> <p id="demo"></p> <script> var ...

Eliminating unnecessary CSS classes

There are multiple references to the specific ".wiki-content" class in the stylesheet: .wiki-content ul,.wiki-content ol,.wiki-content dl { padding-top:0; margin-top:0; } .wiki-content a,.wiki-content a:link,.wiki-content a:visite ...

What is the best way to save news stories along with images in MongoDB?

While this may be a straightforward query for some, I have dedicated my entire day to scouring the internet in search of a suitable response. My current project involves developing a news web application with ReactJS as the front-end, NodeJS Express as t ...

Setting up Storybook with Tailwindcss, ReactJS and Typescript: A comprehensive guide

What is the best way to configure Storybook to handle Tailwindcss styles and absolute paths? Just a heads up, this question and answer are self-documenting in line with this. It was quite the process to figure out, but I'm certain it will help others ...

Arrange the columns in the Table in both ascending and descending order

While working on my React and MUI Table project, I encountered an issue with implementing sorting functionality for each column in both ascending and descending order. Whenever I click on the header to sort a column, an error message saying "Data is not it ...

When triggered by a click, the function gradually fades in and out. It superimposes one image on top of another, but unfortunately, the sizes

Due to different screen sizes, the image does not appear on top of another image exactly. It seems like a new function is needed. One that does not overlap with another image (by clicking the function for a few seconds), but rather replaces it for those fe ...

Beautiful ExpressionChangedAfterItHasBeenCheckedError

I need your help Input field where I can enter a Student email or IAM, which will be added to a string array List displaying all the students I have added, using a for loop as shown below Delete button to remove a student from the array The list has a sp ...