ReactJS is having trouble with inline animation styles

After successfully implementing a timer using CSS with animation, everything was working as expected. However, I encountered an issue when trying to convert it into JSX inline styles in React. The animation stopped working as smoothly as before due to the dynamic nature of the animation duration.

<div className="wrapper">
    <div className="pie spinner" style={{
            animationDuration: `${sessionTimeout}s`,
            animationTimingFunction: "linear",
            animationDelay: `0s`,
            animationIterationCount: "infinite",
            animationDirection: "normal",
            animationFillMode: "none",
            animationPlayState: "running",
            animationName: "timer__rotate"
        }}></div>
        <div className="pie filler" style={{
            animationDuration: `${sessionTimeout}s`,
            animationTimingFunction: `steps(1)`,
            animationDelay: `0s`,
            animationIterationCount: "infinite",
            animationDirection: "reverse",
            animationFillMode: "none",
            animationPlayState: "running",
            animationName: "timer__opacity"}}></div>
        <div className="mask" style={{
            animationDuration: `${sessionTimeout}s`,
            animationTimingFunction: `steps(1)`,
            animationDelay: `0s`,
            animationIterationCount: "infinite",
            animationDirection: "normal",
            animationFillMode: "none",
            animationPlayState: "running",
            animationName: "timer__opacity"}}></div>
        <div className="timer">
            <div className="remaining_time">
                {sessionTimeout}
            </div>
            <div className="time">
                Seconds
            </div>
        </div>
    </div>
    

CSS

.wrapper {
        position: relative;
        margin: 40px auto;
        background: #fff;
    }
    .wrapper, .wrapper * {
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
    }
    .wrapper {
        width: 125px;
        height: 125px;
    }
    .timer{
        position: absolute;
        top: 25%;
        left: 25%;
        z-index: 4;
        text-align: center;
    }
    .timer .remaining_time{
        font-size: 1.8rem;
        font-weight: bold;
    }
    .timer .time{
        font-family: Roboto;
        line-height: 14px;
        text-align: center;
        font-size: 17px;
        margin-bottom: 0px;
        color: #000;
    }
    .wrapper .pie {
        width: 50%;
        height: 100%;
        transform-origin: 100% 50%;
        position: absolute;
        background: #f3f3f3;
        border: 5px solid rgba(2, 155, 237, 1);
    }
    
    .wrapper .spinner {
        border-radius: 100% 0 0 100% / 50% 0 0 50%;
        z-index: 2;
        border-right: none;
        /* animation: timer__rotate 60s linear infinite; */
    }
    
    .wrapper:hover .spinner,
    .wrapper:hover .filler,
    .wrapper:hover .mask {
        animation-play-state: running;
    }
    
    .wrapper .filler {
        border-radius: 0 100% 100% 0 / 0 50% 50% 0;
        left: 50%;
        opacity: 0;
        z-index: 1;
        /* animation: timer__opacity 60s steps(1, end) infinite reverse; */
        border-left: none;   
    }
    
    .wrapper .mask {
        width: 50%;
        height: 100%;
        position: absolute;
        background: inherit;
        opacity: 1;
        z-index: 3;
        /* animation: timer__opacity 60s steps(1, end) infinite; */
    }
    
    @keyframes timer__rotate {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
    @keyframes timer__opacity {
        0% {
            opacity: 1;
        }
        50%, 100% {
            opacity: 0;
        }
    }

Answer №2

In my opinion, specifying animation style in the CSS file is a more effective approach than using inline style, as it helps in organizing your code and avoiding clutter. Additionally, using shorthand animation properties can enhance the readability of your code and make it more concise.

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

Removing a value from an array on click and restricting input tags to only accept numbers with ReactJS

I am currently exploring front-end development and working on expanding my knowledge in this area. I have encountered two challenges that I could use some assistance with, but before I explain further, here is the code snippet: import React, {useState, use ...

The next-auth 4 session is returning null in a next.js environment

Here is the code snippet from api/auth/[...nextAuth].js import NextAuth from "next-auth"; import CredentialsProvider from "next-auth/providers/credentials"; import User from "@/models/user"; import connectToDb from "@/con ...

Unable to replace default typography in MUI with custom typography theme on Next.js

In my Next.js React project, I am utilizing Material-UI (MUI) with a customized theme. Although the colors from the theme are being applied successfully, I am encountering difficulty in adjusting the default font sizes of H2 and H5 elements. Even though I ...

Having trouble while setting up my inaugural React project using the commands npx and npm

I am continuously encountering these errors Attempting to build my first React app, but having no luck Here is a list of the errors I keep facing: npm ERR! could not determine executable to run npm ERR! C:\Users\acer\AppData\Loca ...

Can someone explain why formik forms do not function within material-ui components?

Utilizing Axios to fetch data from an API for the input value, even with the enableReinitialize set to true, poses two challenges: The input does not update as intended The validation using Yup fails to work How can these issues be resolved? const va ...

React JS - Breaking down the distinction between PublicTheme and PublicTheme

In my React project, I am currently working on creating the admin dashboard and designing the UI area for user interaction. I have encountered an issue where I am unable to separate the admin theme from the PublicTheme. Even when navigating to "/admin/lo ...

What is the process for logging out when a different user signs in using Firebase authentication in a React Native application?

I am new to React Native and facing challenges with managing authentication state in my application. Currently, I am using Redux but have not yet implemented persistence for user login. I have incorporated Firebase authentication. Essentially, I would li ...

The fix for the unresponsive fixed container in Angular 2 Material

I've encountered an issue with CSS and Angular 2 material. Any element with a fixed position doesn't behave as expected inside an md-sidenav-container. However, when it is placed outside the container, it works perfectly. I have created a Plunker ...

Using jQuery's .html function to insert images

I have a unique counter that counts in currencies, such as Yen and Euro. Each number, as well as the currency sign and separator, are all displayed on the webpage using custom-designed icons. I utilize the display: flex; property in my container div and ap ...

Implementing the Reactjs module CSS with multiple class selectors

When I click a button, I am trying to implement or add multiple classes to our container. However, the styling does not seem to be applied correctly. Here is the code snippet: Layout.module.css .Content { padding-left: 240px; min-height: calc(10 ...

Is there a way to assign a specific color to individual users in a chat?

I have successfully implemented a chat feature using Pusher, but now I want to customize the appearance by changing the color of the username for the logged-in user when they are active in the conversation. Currently, both my username and another user&apos ...

Tips for concealing the Bottom bar action in React Native

Currently facing an issue with React Native - I need to hide the bottom action bar located just below my tab bar navigation. I'm trying to create a clone of the Disney + App and this particular problem has me stuck: Here's the bottom part of my ...

Hovering over rounded corners is being blocked by transparent areas

I have a setup that resembles the following: http://jsfiddle.net/NhAuJ/ The issue arises when hovering near the edges of the circle because the square div blocks interaction with the background. I want to ensure that the circular div in the middle remain ...

Ways to insert additional panels prior to and after a selected panel

A button is provided in the report designer detail band that, when clicked, should add new panels immediately before and after the detail panel. $parentpanel = $this.parents(".designer-panel:first"); This code snippet is used to locate the parent panel u ...

Is there a way to switch the cursor to a pointer when hovering over a bar on a ChartJS bar graph?

Here's the chart I created: createChart = function (name, contributions, idArray) { globalIdArray = idArray; var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: "bar", data: { lab ...

Icon alignment to wrapped text width has been successfully achieved with the implementation of Flexbox onto a single

I am facing an issue with text wrapping within a flexbox. I want the width of the flex item to always match the length of the wrapped text so that an icon placed next to the item stays adjacent to the text. However, due to text wrapping, there is a gap bet ...

Update the appearance of a webpage using a custom JavaScript function

My goal is to modify a CSS style whenever a button is clicked. In order to achieve this, I have implemented a JavaScript function that creates a new class for CSS along with several other functionalities. Here's how the JS function currently appears: ...

Loading CSS files conditionally in Angular2's index.html

Currently, my index.html page features a dark theme: <base href="/"> <html> <head> <title>XXX</title> </head> <body> <link rel="stylesheet" type="text/css" href="assets/dark_room.css"> <my-app ...

Bootstrap: Troubleshooting Margin Problems

I am currently utilizing the Bootstrap sb admin template. I attempted to include 3 columns in a row, but encountered the issue of them being merged together with no space around them. I experimented by modifying the Bootstrap file through a CDN link and pr ...

Navigate to a refreshed version of the page with varying parameters using React Navigation

Currently, I am utilizing React Navigation for navigating between different pages within my app. One of the pages is the Profile page which displays a user info card along with their posts. Within this Profile component, I have integrated the Post componen ...