Creating engaging animations with styled components in ReactJs

I have embarked on the journey of crafting a testimonial section that bears resemblance to the testimonials displayed on the website www.runway.com. Leveraging styled-components, I've made progress in piling up the cards at the center of the screen, where they gracefully ascend from the bottom to the middle with a seamless linear animation upon entering the view. However, what captivates me about the aforementioned website is its scrolling functionality - as users gradually scroll down, the cards elegantly emerge one after another from the bottom of the screen.

//

import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import ticket from "./assets/ticket0.webp";

const TestimonialSection = styled.section``;

const TestimonialDiv = styled.div`
height: 80vh;
margin: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
min-height: 70%;
`;

const BottomCenter = styled.div`
display: flex;
align-items: center;
justify-content: center;
width: 100%;
@keyframes splash {
    from {
        transform: translate(0%, 100%);
    }
    to { 
        transform: rotate(var(--rx));
    }
}

img{
    width: 0%;
    position:absolute;
    transform:rotate(0deg);
}

.f-image-25{
    width:15%;
    --rx: -3deg;
    z-index:25;
    animation: splash 1s normal forwards ease-in-out;
}
.f-image-35{
    width:17%;
   --rx: -3deg;
    z-index:35;
    animation: splash 1s normal forwards ease-in-out;
}
.f-image-40{
    width:20%;
    --rx: 3deg;
    z-index:40;
    animation: splash 1s normal forwards ease-in-out;
}
.f-image-30{
    width:17%;
    --rx: -6deg;
    z-index:30;
    animation: splash 1s normal forwards ease-in-out;
}
.f-image-20{
    width:15%;
    --rx: 10deg;
    z-index:20;
    animation: splash 1s normal forwards ease-in-out;
}
`;

const Testimonial = () => {

const [isAnimated, setIsAnimated] = useState(false);
const options = {
    root: null,
    margin: '0px',
    threshold: 0.5
}

const observerCallback = (entries) => {
    const [mockImg] = entries

    if (!isAnimated) {
        setIsAnimated(true);
        if (mockImg.isIntersecting) {
            document.getElementById('f-image-40').classList.add('f- image-40')
            document.getElementById('f-image-35').classList.add('f-image-35')
            document.getElementById('f-image-30').classList.add('f-image-30')
            document.getElementById('f-image-25').classList.add('f-image-25')
            document.getElementById('f-image-20').classList.add('f-image-20')
        }
    }
}

useEffect(() => {
    const fImage = document.getElementById('f-image')
    const observer = new IntersectionObserver(observerCallback, options)
    observer.observe(fImage)
    return () => {
        observer.unobserve(fImage);
    }
}, [])

return (
    <TestimonialSection>

        <TestimonialDiv>

            <BottomCenter id='f-image'>
                <img alt="testimonial-card" id='f-image-25' src={ticket}></img>
                <img alt="testimonial-card" id='f-image-35' src={ticket}></img>
                <img alt="testimonial-card" id='f-image-40' src={ticket}></img>
                <img alt="testimonial-card" id='f-image-30' src={ticket}></img>
                <img alt="testimonial-card" id='f-image-20' src={ticket}></img>
            </BottomCenter>

        </TestimonialDiv>

    </TestimonialSection>
)
}

export default Testimonial

Answer №1

If you're looking for a great option to explore in React development, I recommend checking out the Framer library.

By combining the useInView hook with the animate function provided by Framer, you'll have powerful tools at your disposal. This library is well-suited for various situations and offers an array of hooks and functions to enhance your projects.

For more information, visit:

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

Book Roulette: Your Next Random Read

I created a code for a random quote generator and now I want to create something similar, but with images this time. I am looking to add a feature on my page where it can recommend a book by displaying its cover image when a button is clicked. For the pre ...

Most effective method for storing large volumes of data within JavaScript objects

To uniquely identify each item, I need to store data using 3 keys. In this example, I am using i, j, z as the keys. console.time('global1'); var global1 = {}; for (var i = 0; i < 100; ++i) { for (var j = 0; j < 100; ++j) { for (va ...

What are alternative ways to retrieve data from a different server using AJAX without relying on JSONP?

I am currently dealing with a project where the back-end code is located on ServerA, while my front-end code is on ServerB, belonging to different domains. Due to the same origin policy, I am facing difficulties in successfully making AJAX requests (both P ...

Setting up custom fonts in MUI v5: A step-by-step guide

I have the following: const theme = initiateTheme({ typography: { allTypes: CustomFont, fontFamily: 'CustomFontStyle' } as TypographyStyles, components: { MuiFormControl: { styleUpdates: { root: { fontFam ...

Angularjs failing to display data from $rootscope

I encountered some issues while working on a project. Specifically, I faced a problem with the header not allowing me to receive a response, similar to a CORS issue. I was able to resolve this by adjusting the header and using transformRequest as shown in ...

Modifying the image height in a column using Bootstrap and JSON data

My webpage is dynamically generating images from a JSON file through a JavaScript file. However, the images are displaying at different heights, and I want each column to adjust to the height of the image to eliminate any gaps. Particularly, data with the ...

A guide to implementing v-for with intervals in Quasar carousel components

I need help making my blog summary page more dynamic by using a q-carousel to display 3 blog posts per slide. I want to create an array with all the blog posts and loop through it with v-for to populate each slide dynamically while keeping the pagination l ...

The removal of the Button class does not result in immediate rendering

I built a Vue application that displays a button on the screen using Bulma for styling. Upon page load, the button is correctly styled with solid red color and white text since the "is-outlined" class is not present. However, when I click the button, it sh ...

Navigational strip within the grid

My grid has a size of 300px. When there are more than 10 records, a vertical scroll bar appears, which is fine. However, at the same time, a horizontal scroll bar also appears, which I do not want to display. My CSS class for vertical scrolling is: .vstyl ...

What adjustments can I make to my jQuery code in order to animate the mobile menu when it is initially clicked?

I have been using the following mobile menu code for some time now and it has been working well. I have implemented a CSS animation so that when the menu button is clicked, it smoothly scrolls into view. However, I have noticed that the animation does not ...

Triggering PHP functionality in JavaScript when a button is clicked

Struggling to run PHP code inside JavaScript with button onclick event. I have a pair of pages named test.php and demo.php, each containing a button. My goal is to disable the button in demo.php when the button in test.php is clicked. Moreover, upon reload ...

Accessing and manipulating a scope variable in Angular from an external source

Can you update a $scope variable in a controller from an external source? For instance, suppose we have the following controller: app.controller('citySelectCtrl', ['$scope',function($scope){ }]); And there is a function in the globa ...

Is the AJAX function failing to execute? Potential issue with the database connection?

I am currently working on setting up my project on the localhost. I've encountered an issue with the built-in ajax function upon success. Below is the snippet of the javascript function in question: function fetchResults(page, searchString) { page ...

Utilizing Javascript to collapse the initial DIV element discovered with a specific classname

Seeking assistance with this particular Javascript code. The objective is to collapse the next element. Unfortunately, it is not functioning as expected due to an error in closing the first DIV in each block. The script should aim to collapse the initial ...

Bring in a 3D design utilizing an entry input

I'm looking for a way to dynamically import 3D models (like stl, obj, and mtn) using an input feature. Currently, I have hard-coded the paths for the models using props like pathModelObj and pathModelMtl. However, I wish to make this process more dy ...

How can I eliminate the space between the navbar and toggle menu item in Bootstrap 4?

Upon experimenting with Bootstrap 4, I came across the default navbar template. While using it for learning purposes, I encountered difficulties when trying to modify or style the CSS. I'm having trouble understanding why there is a gap between the na ...

Enhancing the visual appeal of Struts 2 with property tag styling

Utilizing the Struts2 property tag to fetch the user's name, my code looks like this. <div class="MyStyle"> <p> Hi! <s:property value="#session.firstName"/></p> </div> However, I am facing an issue wh ...

PayPal Integration with React for Seamless Checkout Experience

I established a small and uncomplicated online store featuring a PayPal checkout system, and it is functioning adequately. Now, I am looking to include detailed information about the purchased products in the transaction history of my PayPal account. This ...

Jquery menu block shift

I am looking to implement a timer for the submenu within my menu. The idea is to show the submenu for 3 seconds after a mouse-over event. I have already set up a function to display and hide the submenu, but I am facing an issue where the submenu shifts to ...

Exploring the idea of how a Node.js server works

Although I have a good understanding of jQuery, I am new to modern JavaScript frameworks that have been introduced in the past few years. In the example provided, I can see how index.html functions and how server.js handles requests from it. However, I am ...