Tips for integrating CSS keyframes in MUI v5 (using emotion)

Hey there! I'm currently working on adding some spinning text, similar to a carousel, using keyframes in my React app. The setup involves MUI v5 with @emotion. Basically, I want a "box" element to show different words every few seconds with a rotating animation effect. Check out the code snippet below for the keyframes of my spin animation:

import { css, keyframes } from '@emotion/react';
export const Home = () => {
    const spin = keyframes`
        0%, 20%:{
            transform: translateY(0)
        },
        25%, 45%:{
            transform: translateY(-208px)
        },
        50%, 70%:{
            transform: translateY(-416px)
        },
        75%, 95%:{
            transform: translateY(-624px)
        },
        100%:{
            transform: translateY(-832px)
        }
    `;
    const animated = css`
        animation: ${spin} 7s ease-in-out infinite;
    `

Here's what the components look like once returned:

return (<>
        ...
        <div css={animated}>
            <div>restaurants</div>
            <div>musuems</div>
            <div>landmarks</div>
            <div>parks</div>
        </div>
        ...
</>)

My goal is to eventually swap out the div elements with MUI's Box and Typography components. This is my first time working with keyframes, especially when it comes to integrating them with MUI. Any guidance or tips would be highly appreciated :)

Answer №1

Give this code a shot using emotion/styled

import styled from "@emotion/styled";
import { keyframes } from "@emotion/react";

export const Home = () => {
    const spin = keyframes`
        0%, 20%:{
            transform: translateY(0)
        },
        25%, 45%:{
            transform: translateY(-208px)
        },
        50%, 70%:{
            transform: translateY(-416px)
        },
        75%, 95%:{
            transform: translateY(-624px)
        },
        100%:{
            transform: translateY(-832px)
        }
    `;

 const StyledDiv = styled.div`animation: ${spin} 7s ease-in-out infinite`; 
 return (<>
        ...
        <StyledDiv>
            <div>restaurants</div>
            <div>musuems</div>
            <div>landmarks</div>
            <div>parks</div>
        </StyledDiv>
        ...
</>)

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

What steps can be taken to fix the recurring node error "EADDRINUSE"?

Having trouble running an http server through node as I keep encountering the EADDRINUSE error specifically on port 5000. I've attempted using sudo lsof -i tcp:5000 and sudo kill -9 [PID]. Here's a snippet of the shell command: Borealis:BackEnd g ...

Best methods for deleting an element's attribute or style attribute

Imagine this snippet of CSS code: .notif-icon { display: inline-block; } In my HTML, I have the following element which starts off hidden by overriding the display property of the notif-icon class: <span id="error" class="notif-icon& ...

Recalling the layout following the user's computer restart

I am creating a simple online editing tool (similar to Microsoft Outline) for coursework and I would like the outline details to be saved even if the user restarts the system. How can I achieve this? <html> <head> <title>Editor</ ...

Managing HTTP errors using async/await and the try/catch block in a React application with TypeScript

Below is a snippet of code I am working with! import React, { useState } from "react"; function App() { const [movies, setMovies] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState<string ...

Error: Attempting to assign a value to a property of #<Object> that is read-only

I'm working on a task management application and encountering an issue when trying to assign an array of tasks stored in localStorage to an array named todayTasks. The error message being thrown is causing some disruption. https://i.sstatic.net/uFKWR. ...

Fetching content-type in React code locally executed

I am a beginner in front end development and I need help with setting the "application/json" content-type and gzip content-encoding in the fetch call for my locally run React code. Can anyone provide guidance on this? const data = await fetch(url, { ...

Headers and data organization in Angular 2

I'm searching for a simple Angular 2 example that demonstrates how to fetch both the headers and data from a JSON API feed. While there are plenty of examples available for fetching data only, I haven't been able to find any that show how to retr ...

Trying to access the 'style' property of a null value is causing an error

Although I have come across several questions related to this particular error, unfortunately, none of them provided a solution. Below is the HTML code: <!DOCTYPE html> <html> <head> <title>ChatRoom</title> <link ...

Issue with the flexbox div not fully occupying the vertical space

I can't seem to get flexbox to fill the spaces as I want it to. I've been trying to figure out what I'm missing, but I just can't wrap my head around it. Here's a recreation of the issue with a link to a codepen. I want the div in ...

The input group addon is not displaying properly in the Mozilla browser

I am presenting the following data in a table: <table class="neo-table"> <tr> <td>Day of final discharge home</td> <td>{{ form_widget(form.mHomeDischargeDay, {'id': 'M_Home_discharge_day', ' ...

Ways to isolate AngularJS files without relying on the global scope

I came across a post on Stack Overflow discussing the best practices for declaring AngularJS modules. Despite reading it, I am still unsure about the most effective way to separate and declare angularJS files for modules, controllers, services, etc. I hav ...

Selecting CSS Properties with jQuery

I am trying to make an image change color to blue and also change the background color to blue when it is clicked inside a div. However, my code doesn't seem to be working as expected. Is there a more efficient way to apply CSS to elements? FIDDLE v ...

Making poll everywhere items align horizontally using HTML: a step-by-step guide

Is there a way to display two different Poll Everywhere polls side by side on a Blackboard course, rather than having them stacked on top of each other? I have the embed codes for both polls ready to go. ...

The Ionic React application is unable to identify the Leaflet Plugin

I'm currently stuck on this issue: I am trying to incorporate the Leaflet plugin, AwesomeMarkers, into my Ionic-React application. Following the instructions in the plugin's documentation, I have included FontAwesome, the plugin JS file, and the ...

Tips on fixing image movement when scrolling and switching resolutions

I am currently working on developing my HTML/CSS portfolio. However, I am facing an issue where the images on the site move around whenever the scroll level or resolution size is changed. I want the images to remain in their respective blocks, displayed at ...

Tips for transferring i18n or t function to a dependency in next-i18next

I am faced with a situation where I have two repositories. One repository contains a nextjs application, while the second one houses components that are dynamically loaded into the first repo. Among these components in the second repository are some that ...

"Enhance your listening experience with an audio player featuring album covers as captivating

Is there a way to create an audio player with the album cover image serving as the background, while ensuring all control buttons are displayed on top of that same image? I attempted using the following code snippet: <audio controls = 'controls&ap ...

Using AngularJS and SpringMVC for uploading multiple files at once

Having recently delved into the world of angularJS, I've been attempting to upload a file using angular JS and Spring MVC. However, despite my efforts, I have not been able to find a solution and keep encountering exceptions in the JS Controller. Bel ...

What is the best way to stop an embedded mp4 video from playing when a dynamically generated button is clicked?

After making modifications to the QuickQuiz code found at https://github.com/UrbanInstitute/quick-quiz, I have replaced the img with an embedded mp4 video that loads from a JSON file. Additionally, I switched from using the original SweetAlert library to S ...

Automatically fill out form fields by selecting data from a spreadsheet

I successfully created a web application using Google Apps Script (GAS) that sends data on submission to Spreadsheet A. Furthermore, I have implemented a select option that dynamically fetches data from another spreadsheet B ("xxx") in column A. Below is ...