Resetting CSS animations using animation-delay

My aim is to animate a series of images on my landing page using Next.js and SCSS. The issue arises when I try to add dynamic animations that reset after each cycle. The delay in the animation causes the reset to also be delayed, which disrupts the flow. Is there a way to include the delay within the running animation cycle, so that when it reaches the end, all elements reset simultaneously before adhering to the delay again? Below is the code snippet I am working with:

Carousel.js:

import Image from 'next/image';
import styles from '@/styles/components/LandingCarousel.module.scss';

export default function LandingCarousel() {

    const images = [
        { src: '/NetworkingSkeleton.png', delay: 6 },
        { src: '/NetworkingSkeleton.png', delay: 7 },
        { src: '/NetworkingPreview.png', delay: 8 },
        { src: '/NetworkingSkeleton.png', delay: 9 },
        { src: '/NetworkingSkeleton.png', delay: 10 },
        { src: '/NetworkingSkeleton.png', delay: 11 },
        { src: '/NetworkingSkeleton.png', delay: 12 },
        { src: '/NetworkingPreview.png', delay: 13 },
        { src: '/NetworkingSkeleton.png', delay: 14 },
        { src: '/NetworkingSkeleton.png', delay: 15 },
    ];

    const listingImages = [
        { src: '/ListingSkeleton.png', delay: 6 },
        { src: '/ListingSkeleton.png', delay: 7 },
        { src: '/ListingPreview.png', delay: 8 },
        { src: '/ListingSkeleton.png', delay: 9 },
        { src: '/ListingSkeleton.png', delay: 10 },
        { src: '/ListingSkeleton.png', delay: 11 },
        { src: '/ListingPreview.png', delay: 12 },
        { src: '/ListingSkeleton.png', delay: 13 },
    ];

    return (
        <div className={styles.section}>
            <div className={styles.container}>
                {images.map((image, index) => (
                    <img
                        key={index}
                        src={image.src}
                        className={styles.animated_image}
                        style={{ '--delay': image.delay }}
                    />
                ))}
            </div>
            <div className={styles.containerRight}>
                {listingImages.map((image, index) => (
                    <img
                        key={index}
                        src={image.src}
                        className={styles.animated_imageRight}
                        style={{ '--delay': image.delay }}
                    />
                ))}
            </div>
        </div>
    );
}

LandingCarousel.module.scss:

.section {
    display: flex;
    height: 87vh;
    overflow: hidden;
    align-items: center;

    .container {
        display: flex;
        flex-direction: column;
        height: calc(400px * 5);

        .animated_image {
            display: flex;
            position: relative;
            max-height: 400px;
            object-fit: cover;
            animation: scroll 8s ease-in-out infinite;
            -webkit-animation: scroll 8s ease-in-out infinite;
            // animation-delay: calc(var(--delay) * 0.05s);
            // -webkit-animation-delay: calc(var(--delay) * 0.05s);
        }
    }

    .containerRight {
        display: flex;
        flex-direction: column;
        height: calc(380px * 4);

        .animated_imageRight {
            display: flex;
            max-height: 380px;
            object-fit: cover;
            animation: scrollRight 8s ease-in-out infinite;
            -webkit-animation: scrollRight 8s ease-in-out infinite;
            // animation-delay: calc(var(--delay) * 0.05s);
            // -webkit-animation-delay: calc(var(--delay) * 0.05s);
        }
    }
}

@keyframes scroll {

    0% {
        -webkit-transform: translateY(0);
        transform: translateY(0);
    }

    50% {
        -webkit-transform: translateY(-400px * 5);
        transform: translateY(-400px * 5);
    }

    100% {
        -webkit-transform: translateY(-400px * 5);
        transform: translateY(-400px * 5);
    }
}

@keyframes scrollRight {

    0% {
        -webkit-transform: translateY(0);
        transform: translateY(0);
    }

    50% {
        -webkit-transform: translateY(-380px * 4);
        transform: translateY(-380px * 4);
    }

    100% {
        -webkit-transform: translateY(-380px * 4);
        transform: translateY(-380px * 4);
    }
}

Answer №1

My suggestion would be to manipulate animations using JavaScript, handling delays and repeat intervals, adding or removing classes from parent elements, and utilizing these classes to trigger animations.

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

Ways in which elements can be toggled through jquery or javascript?

There are various words listed below: word1 word2 word3 ... Every word in the list is linked to 1 to 3 examples. When a user clicks on a word, certain actions should take place. I want the examples to display when the associated word (e.g., word1) is c ...

Having trouble adding your own styling to bootstrap-4 using a custom CSS file?

Here is the code I used to connect my two stylesheets, with the custom css file being linked second as per what I believe is the correct way to do it. <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href=" ...

"Exploring the power of dynamic routing with Next.js and

My app has nested dynamic routes and here is the folder structure: Check out a preview of my page (/helpa/business/common-questions): For SEO optimization purposes, when users click on the "Open and manage a shop" subtab, I want them to be redirected to ...

Ways to condense a text by using dots in the middle portion of it

How can I dynamically shorten the text within a container that varies in width? The goal is to replace the strings between the first and last words with dots so that it fits within the container. For example, Sydney - ... - Quito. It should only replace wh ...

What causes the Footer to appear as a floating element in Tailwind CSS?

I've implemented the tailwind CSS footer into my NextJS project to display fetched data. However, I encountered an issue where the footer only floats when there is less data present. To address this problem, I created a separate footer file within my ...

Unusual shadow cast by the box's silhouette

I am currently facing an issue with a box and its shadow. When I close the box, a different shadow lingers behind. I have tried troubleshooting this problem but cannot pinpoint the source. I have included the relevant code files in the specified folders. I ...

Next.js router is redirecting to an incorrect route

Currently, I am implementing role-based authentication in my Next.js application. There are two roles: admin and user. The structure of my pages is organized as follows: ┣ ...

What are the best techniques for styling a SELECT box with HTML and CSS?

I've received a form from a talented designer which includes SELECT inputs designed in a unique manner. Despite my attempts to add paddings, adjust backgrounds, I'm unable to replicate the exact appearance of the select box shown in the image. ...

Error encountered: Prisma seed operation timed out while running the Github action that is aimed at populating

Currently in the process of transitioning a Postgres database from AWS RDS to Vercel for a Nextjs project utilizing Prisma. After successfully executing the db seed command from my local machine, following the recommended env variables provided by Vercel& ...

Getting the value of a form input in React.js is a common task that can

Currently, I am working with Reactjs and using the nextjs framework. As part of my project, I have a form where I am encountering an issue related to getting the value of an input type text field. When I try to access the value, I see the following error o ...

How to send multiple queries in one request with graphql-request while using getStaticProps?

I am currently utilizing graphCMS in combination with NextJS and have successfully implemented fetching data. However, I am facing an issue where I need to execute 2 queries on the homepage of my website - one for all posts and another for recent posts. q ...

Create dynamic flex transitions

After searching through various CSS resources and websites, I haven't found an answer to my specific query. I have been exploring CSS tricks as well as http://n12v.com/css-transition-to-from-auto/ but still uncertain if what I'm looking to achiev ...

Is the order of elements in a CSS file important?

In my situation, I am dealing with a nested list and enclosing div that was created by Drupal's menu system, so I am unable to modify it. My goal is to replicate the menu from a hardcoded website (link removed). How can I include the sub-items (ul l ...

Convert TypeScript-specific statements into standard JavaScript code

For my nextjs frontend, I want to integrate authentication using a keycloak server. I came across this helpful example on how to implement it. The only issue is that the example is in typescript and I need to adapt it for my javascript application. Being u ...

Ways to customize background color for a particular date?

I have been using the fullcalendar npm package to display a calendar on my website. I am trying to figure out how to set a background color for a specific selected date. I tried looking into this issue on GitHub at this link. However, it seems that dayRe ...

Tips for making markers act responsively

Recently, I put together a collection of rain radar images that can quickly show whether rain is on the way or not. As you resize the URL window, the two pictures positioned side by side will also shrink. For an illustration, check it out here ... Each p ...

Tips for fading an image as you scroll using CSS and JavaScript?

I have been dedicating my day to mastering the art of website development. However, I am facing a challenge that is proving to be quite difficult. I am looking to create a smooth transition effect where an image gradually blurs while scrolling down, and re ...

Adaptable design tailored for smartphones

When it comes to developing mobile websites for various platforms such as iPhone 3 and 4, Android, Blackberry Torch, etc., I usually find myself needing to slice images based on the specific platform. The challenge arises from constantly having to slice im ...

The use of `import { Provider as AuthProvider } from "next-auth/client"` is causing an issue within the `_app.js` file and

Currently, I am watching a video on authentication at the 39-minute mark: Watch Video. The authentication part is shown in _app.js. Upon trying to import { Provider as AuthProvider } from "next-auth/client", I encountered the following error mes ...

The getStaticProps function will generate an object by fetching data from various URLs

Within my getStaticProps function in next js, I am faced with the challenge of fetching multiple dynamic URLs and exporting the results as props to the component. As these URLs are automatically generated, I do not know how many there will be to fetch. My ...