Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
how to apply the same keyframe animation name into 2 class

I have one boolean variable to control the fade in effect for two components. however, if I use the same keyframe name for animation it does not work. I have to create duplicated keyframe context for two fade in effect. anyone know why or how can I clean up my css file? codesandbox.io

// App.tsx
import "./styles.css";
import { useState } from "react";
import classNames from "classnames";

export const HalfPage = () => {
  return (
      <h1>I am half page context</h1>
  );
};

export const FullPage = () => {
  return (
      <h1>I am FULL page context</h1>
  );
};
export default function App() {
  const [cnt, setCnt] = useState(0);
  const isFullPage = cnt % 2 === 0;
  const appClass = classNames({
    fullPage: isFullPage,
    halfPage: !isFullPage
  });
  const handleOnClick = () => {
    setCnt(cnt + 1);
  };
  return (
    <div className="App">
      <button onClick={handleOnClick}>Change background</button>
      <div className={appClass}>{isFullPage ? <FullPage /> : <HalfPage />}</div>
    </div>
  );
}


// css

.fullPage {
  background-color: aquamarine;
  animation: fullFadeIn 2s linear;
  /* animation: fadeIn 2s linear; it does not work*/
  width: 490px;
}
.halfPage {
  background-color: bisque;
  animation: halfFadeIn 2s linear; /*it does not work*/
  /* animation: fadeIn 2s linear; it does not work*/
  width: 290px;
}
@keyframes halfFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fullFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!