Creating an array of logos in ReactJS with the help of TailwindCSS

After seeing multiple implementations of this feature, I find myself struggling to search for a solution. I can only access the HTML and CSS through inspecting elements, wondering if others are facing the same issue as me.

Typically, we aim to implement this feature to showcase previous clients or portfolio items.

The current implementation works but there is always a stutter every time it loops through the array of images. Below is my React components:


const clients = [
    {
        name: 'google',
        logo: Google,
    },
    // Additional client objects
];

 <div className='overflow-hidden py-8'>
                    <div className='flex animate-left'>
                        <div className=" flex w-max  gap-8 mr-4">
                            {clients.map((client, index) => (
                                <a key={index} href="#" className="flex justify-center items-center shadow-md rounded-xl p-6 w-[10rem] ">
                                    <Image src={client.logo} alt={client.name} width={100} height={100} className="w-full h-full object-contain" />
                                </a>
                            ))}
                        </div>
                        <div className=" flex w-max   gap-8  ">
                            {clients.map((client, index) => (
                                <a key={index} href="#" className="flex justify-center items-center shadow-md rounded-xl p-6 w-[10rem] ">
                                    <Image src={client.logo} alt={client.name} width={100} height={100} className="w-full h-full object-contain" />
                                </a>
                            ))}
                        </div>
                    </div>
                </div>

Here's my Tailwind config :

    extend: {
      animation: {
        'left': 'bannermoveleft 20s linear infinite',
      },
      keyframes: {
        bannermoveleft: {
          '0%': { transform: 'translateX(0)' },
          '100%': { transform: 'translateX(-50%)' },
        }
      },

Answer №1

Utilize the width: max-content property on the scrolling element with w-max to ensure that the -50% value in the transform of bannermoveleft corresponds to the width of one of the cloned items.

Add gap: theme(spacing.8) using gap-8 to the scrolling element and eliminate the mr-4 from the first clone group, ensuring consistent spacing between the clones and items.

Adjust the translateX() function in bannermoveleft by subtracting half of the gap, allowing for a seamless transition until the left edge of the second clone group aligns with the start of the animation loop:

tailwind.config = {
  theme: {
    extend: {
      animation: {
        'left': 'bannermoveleft 5s linear infinite',
      },
      keyframes: {
        bannermoveleft: {
          '0%': { transform: 'translateX(0)' },
          '100%': { transform: 'translateX(calc(-50% - (theme(spacing.8) / 2)))' },
        }
      },
    },
  },
};

const Google = 'https://picsum.photos/100/100';
const Asus = 'https://picsum.photos/100/100?';
const Byu = 'https://picsum.photos/100/100?0';
const Kominfo = 'https://picsum.photos/100/100?1';
const Telkom = 'https://picsum.photos/100/100?2';
const Bi = 'https://picsum.photos/100/100?3';

const clients = [
    {
        name: 'google',
        logo: Google,
    },
    {
        name: 'asus',
        logo: Asus
    },
    {
        name: 'byu',
        logo: Byu,
    },
    {
        name: 'kominfo',
        logo: Kominfo
    },
    {
        name: 'Telkom',
        logo: Telkom,
    },
    {
        name: 'Bank Indonesia',
        logo: Bi,
    },
    // Add more clients as needed
];

function App() {
  return (
    <div className='overflow-hidden py-8'>
      <div className='flex animate-left gap-8 w-max'>
        <div className=" flex w-max gap-8">
          {clients.map((client, index) => (
            <a key={index} href="#" className="flex justify-center items-center shadow-md rounded-xl p-6 w-[10rem] ">
              <img src={client.logo} alt={client.name} width={100} height={100} className="w-full h-full object-contain" />
            </a>
          ))}
        </div>
        <div className=" flex w-max gap-8">
          {clients.map((client, index) => (
            <a key={index} href="#" className="flex justify-center items-center shadow-md rounded-xl p-6 w-[10rem] ">
              <img src={client.logo} alt={client.name} width={100} height={100} className="w-full h-full object-contain" />
            </a>
          ))}
          </div>
        </div>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('app')).render(<App/>);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js" integrity="sha512-8Q6Y9XnTbOE+JNvjBQwJ2H8S+UV4uA6hiRykhdtIyDYZ2TprdNmWOUaKdGzOhyr4dCyk287OejbPvwl7lrfqrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js" integrity="sha512-MOCpqoRoisCTwJ8vQQiciZv0qcpROCidek3GTFS6KTk2+y7munJIlKCVkFCYY+p3ErYFXCjmFjnfTTRSC1OHWQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.tailwindcss.com/3.3.3"></script>

<div id="app"></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

Stop the page from scrolling

I'm trying to find a way to disable page scrolling, so I used this style for the body: overflow: hidden; Surprisingly, it worked perfectly on desktop but had no effect on mobile devices. After checking out this resource, it seems that creating a ch ...

Uploading a Node.js Package to GitHub Packages - Issue ENEEDAUTH

Hello everyone, I am currently attempting to deploy my NPM package to GitHub packages using the following yaml configuration: # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created # For m ...

Is it possible for me to generate HTML using JavaScript?

Below is the javascript code I have written, saved as create.js: var stuff = document.querySelector(".stuff"); var item = document.createElement('div'); item.className = 'item'; stuff.appendChild(item); This is the corresponding HT ...

Developing a vanilla JavaScript web component with distinct HTML and JavaScript files

As I delve into creating vanilla JS web-components, I am exploring methods to keep the template HTML separate from the JS file, ideally in a distinct HTML file. I have examined various implementations of native JS web-component setups found notably here, ...

Center an image both vertically and horizontally within an Owl Carousel arrow slider

I have set up an owl carousel on my page with a customized arrow positioned next to the slider. Currently, it looks like this: https://i.stack.imgur.com/gCfM0.png My goal is to vertically align the arrows and make sure the left arrow is aligned to the le ...

How to manage rejections in async/await within the Array#map method

In my Node 8.1.2 project, I encountered a scenario where one file is calling another file's function within a map structure. While in a real example, I would normally use Promise.all on the map, that specific implementation is not the focus of this qu ...

Auto-scrolling text box cursor movement

My query is quite similar to the topic discussed in this thread on automatic newline in textarea. However, my situation involves multiple textareas with a 1-row attribute, making it seem like writing on air due to the absence of visible borders (I've ...

What is the best way to deduct a variable's previous value from the final value, ensuring that the total value does not surpass a specific limit?

For instance: let num = 20; const sub = 6; const add = 10; num = num - sub; num = num + add; if (num > 20){ num = 20; } console.log("Only 6 was actually added to var num before reaching its maximum value"); Is there a way to adjust the console log ...

Which Express.js template allows direct usage of raw HTML code?

I am in search of a template that utilizes pure HTML without any alterations to the language, similar to Jade but keeping the HTML as is. The reason behind this inquiry is: I prefer the simplicity and clarity of HTML I would like to be able to easily vi ...

Tips for utilizing npm run build in your React application:

I recently put together a small website using a React app. However, when I run npm run build and check the browser's debugger, I see a static folder containing my entire React app, components, app.js, and even node_modules. Clearly, something is not r ...

Position the Bootstrap Button on the right side of the navbar

Hey there, I'm completely new to the world of HTML/CSS and this is my first project ever. I welcome any constructive criticism that can help me improve in the future. Now onto my current dilemma: I've decided to use Bootstrap because it seems u ...

Exploring jQuery's parent selector for traversing the DOM

I am currently working with an array that inserts articles into my website. I have a specific requirement where, upon clicking the title (h3), I need to display more information based on the article's index. To achieve this, I believe I should travers ...

What is the best way to target the shadow DOM host element specifically when it is the last child in the selection?

I want to style the shadow DOM host element as the last child. In this particular situation, they are currently all green. I would like them to be all red, with the exception of the final one. class MyCustomElement extends HTMLElement { constructor() ...

Encountering an issue while attempting to send an image through JavaScript, jQuery, and PHP

I'm currently attempting to upload an image using JavaScript/jQuery, but I am unsure of how to retrieve the image in order to send it to a server (PHP). I have a form containing all the necessary information that I want to save in MySQL, and I use jQu ...

Navigating with Nokia Here maps: plotting a path using GPS coordinates

I am currently developing a GPS tracking system and my goal is to visually represent the device's locations as a route. The challenge I'm facing is that there is a REST API available for this purpose, but my client-side application relies on soc ...

The server encountered an unexpected error while processing the request, possibly due to a

My JavaScript file includes an interval function that calls the following code: setInterval(function() { $.getJSON('/home/trackUnreadMsgs', function(result) { $.each(result, function(i, field) { var temp = "#messby" + result[i].from; ...

How can I make the scrollbar invisible in the sticky header of a Material UI Table?

In my React project, I have implemented a Material-UI Table with a fixed header. The issue I am facing is that the scrollbar in the table header overlaps it and I want to hide it while still displaying it in the body of the table. I have attempted to modi ...

Updating paths dynamically with React Js

I currently have the following imports: import {Input, InputTxtCenter} from '../../../components/forms/input/input.js'; import {ButtonRed} from '../../../components/buttons/'; import {TxtCenter} from '../../../components/misc/text ...

The Calibri Light font is not supported by Chrome version 37

Yesterday my website was working fine, but today when I checked it, some strange issues appeared. The Calibri Light font that I used extensively has been replaced with the default font, and the width of input fields has changed. How can I resolve this issu ...

Encountering a `ECONNREFUSED` error while attempting to dispatch an action in the

I have decided to convert my Nuxt application to SSR in order to utilize nuxtServerInit and asyncData. Below are the steps I followed during this conversion process. Removed ssr: false from nuxt.config.js Dispatched actions to initialize the store's ...