Having trouble retrieving the animation keyframe names from the SCSS file in animate.css

I'm currently experimenting with incorporating animate.css into my React/Next.js project. While I can easily create animations using animate.css's inline class names, I'm facing challenges in calling animate.css's keyframe animations from my scss file. I came across a tutorial on YouTube that demonstrates this, but the difference lies in the fact that I am working with Next.js.

For reference:

https://www.youtube.com/watch?v=ESHaail1eGc&t=4379s&ab_channel=CodewithSloba

The tutorial importer the animate.css file at 3:55 and successfully applied the bounceIn animation from animate.css at 38:31.

Example:

In my styles/globals.scss file, I imported animate.css

@import 'animate.css'

In my AnimateLetters.tsx file, I first import the scss module,

import styles from '../../styles/AnimatedLetters.module.scss'

Within the same file, inside the React component,

This approach works for me:

<span className='animate__animated animated__bounceIn'> H </span>

However, this method does not work:

<span className={styles.animateText}> H </span>

In my AnimatedLetters.module.scss, the styling is defined as:

.animateText {
  display: inline-block;
  animation-name: bounceIn;
  animation-duration: 2s
}

To overcome this issue, one way is to locate the keyframe within the

node_modules/animate.css/animate.css
file and manually copy it into my scss file, as seen below:

@keyframes bounceIn {
  from,
  20%,
  40%,
  60%,
  80%,
  to {
    -webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  }

  0% {
    opacity: 0;
    -webkit-transform: scale3d(0.3, 0.3, 0.3);
    transform: scale3d(0.3, 0.3, 0.3);
  }

  20% {
    -webkit-transform: scale3d(1.1, 1.1, 1.1);
    transform: scale3d(1.1, 1.1, 1.1);
  }

  ...
}

I would prefer to avoid this workaround if possible. Additionally, if I were to proceed with this option, would it be better to uninstall animate.css altogether and simply paste the necessary keyframes into my global.scss?

Answer №1

Given that the bounceIn animation is defined globally (imported from animate.css in your globals.scss), it is necessary to utilize the :global selector when incorporating it into your Sass Modules file. Otherwise, Sass Modules will interpret bounceIn as locally scoped and will generate a hashed animation name.

.animateText :global {
    display: inline-block;
    animation-name: bounceIn;
    animation-duration: 2s
}

/* or */

.animateText {
    display: inline-block;
    animation-duration: 2s
    &:global {
        animation-name: bounceIn;
    }
}

By default, CSS Modules assumes that everything is locally scoped. To access anything globally scoped, the :global selector must be used.

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

How come user CSS in Stylish takes precedence over the author's CSS?

Here's a sample page: <!DOCTYPE html> <html> <head> <style type="text/css"> body { background: black; } </style> </head> <body> </bod ...

Tips for organizing your JSON Structure within ReactJs

In the given example, I have a JSON structure with information about different airlines. The Airline Name is dynamic and we need to separate the JSON into an expected array format. const arr = [ { Airline: "Goair", Departure: "01:50" ...

Hydration Error arises when Next.js SSG Suspense is triggered

My static site is encountering an issue when trying to display a simple list of items retrieved from Supabase. Everything was working fine in React 17, but after upgrading to React 18, I am now getting sporadic errors and the fallback doesn't consiste ...

Highlighting of tab CSS is not persistent when switching tabs or clicking elsewhere on the page

Using Bootstrap 4, a navigation tab is created. However, upon loading the page, the home tab is automatically loaded but not highlighted. Clicking on any tab will highlight it correctly, but once clicked anywhere else on the page, the highlight disappears. ...

Fluid div causing navigation to display improperly

I am currently working on a navigation design where I want to have an image above each list item instead of having individual images for each item. It looks great when the screen is at full size, but as soon as I minimize it, the list items start stacking ...

Setting the height of a child tag: A step-by-step guide

When trying to set the height of a child tag to 100%, I encountered an issue where the height would remain fixed after redirecting to another page, preventing the page from scrolling. Styling for Image 1 body{ background: url("Resources/Cash.jpeg&q ...

What are the steps to deploying a React application on a standard domain, such as http://exampledomain.com/?

Recently, I've been exploring how to host my static React application on the web. I have a domain ready to go at http://somedomainnamehere.com/. However, as a newcomer to React and web hosting, I encountered a roadblock. Despite following tutorials an ...

The background image seems to be malfunctioning

I've been attempting to recreate a similar design to this website, and while most of it is working smoothly, I'm encountering an issue with using ::before to add a background image as desired. Below is the code snippet in question: /* Section ...

What is the best way to include a search box in the mobile view between the brand and menu toggle?

Is there a way to place the search bar between the brand and menu toggle on the mobile view without it appearing on a separate row either under or over the navbar? I've been trying to override some Bootstrap CSS but haven't found a solution yet. ...

Caution: Reactjs detectable issue with unreached code

Have you encountered the warning about unreachable code (no-unreachable) in my ReactJS app? Can anyone help me with this issue? The error seems to be related to an if-else return statement. The problem lies within this section: If there is no Route path ...

Challenges encountered when attempting to send an array in res.json with the MERN stack

I am facing a challenge while trying to make two separate model calls using the MERN stack. The issue arises when I try to send an array in res.json; extracting the data seems to be problematic. On examining the console log: {data: "[]", status: ...

What is the best way to eliminate all hover effects on smaller devices?

What is the solution to remove hover effects on elements in CSS? Consider the following HTML and CSS code: @media (max-width: 1220px) { .column { width: 200px; } .para { display: none; } .link:hover { color: red; } } @media (ma ...

Struggling with determining the perfect transition speed for the sidemenu display

I'm a newcomer to web development and facing an issue with setting the transition speed for opening and closing this side menu. Despite adding transitions in the CSS and specifying duration in the Javascript, the menu continues to open instantly. I di ...

Show specific button text when no file has been selected

I have a form with an image container that allows users to change the photo. The icon opens a file browser, and when the user selects a file, the Change button submits the photo and updates it. https://i.sstatic.net/R5vwn.jpg If no file is selected, I wa ...

Guide to incorporating eslint with Next.js in a project that already has an eslint configuration

I recently created a new next.js project within my existing Node.js project, which already has an eslint config set up. Here's how the folder structure looks now: ...

Error encountered in React: When a parent component tries to pass data to a child

I have a Quiz object that I need to pass a single element of (questionAnswerPair) to a child component called QuestionAnswer. Although the Quiz data is fetched successfully and iterated through properly, there seems to be an issue with passing the Questio ...

In Angular 4 applications, all vendor CSS files are converted into style tags at the beginning of the HTML document

In my Angular 4 project, I have integrated Bootstrap, Fontawesome, and some custom CSS. However, all these styles are rendering as separate tags at the top of my index.html file. I would like them to be combined into a single bundled CSS file for better ...

It seems that the Object.keys and Object.getOwnPropertyNames methods in Javascript (React) are unexpectedly returning an empty

7aubI5jQAOXH1qbcIKar: {createdAt: Timestamp, displayName: "Test1", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="186c7d6b6c29587f75797174367b7775754933585b5f4915757">[email protected]</a>", postData: "sss ...

Creating a React Application with Functional Components integration with Firebase

Looking to create a React Application integrated with Firebase? Utilize Functional Components along with the Material UI library, and incorporate hooks for maintaining authentication state. ...

React-router-dom causing component not to render

I am currently working on setting up different components to render on different routes within my application. Here is a snippet from my index.js file: ReactDOM.render(<Routes />, document.getElementById('root')); The render function in m ...