无法访问scss文件中的动画

发布于 2025-01-29 22:53:38 字数 2250 浏览 6 评论 0 原文

我正在尝试将Animate.CSS与React/Next.js一起使用。我可以使用Animate.css的Inline类名称创建动画,但是我想从我的 scss 文件中调用Animate.css的键帧动画。我正在遵循YouTube指南,他能够做到这一点。唯一的区别是我正在使用next.js。

作为参考:

他在3:55导入 and> and> and> and cosate.css 文件,并且能够使用Animate.css的 bunecin 代码>动画在38:31。

示例:

在我的样式/globals.scss.scss 文件中,我

@import 'animate.css'

andimateletters.tsx 文件中添加 了Animate.css SCSS模块,

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

在同一文件和React组件中,

这对我有用:

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

但这不是:

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

在我的 andimatedletters.module.scss 中,我有

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

一种骇人听闻的方式来解决此问题 node_modules/animate.css/animate.css 文件中的密钥帧,然后将其复制到我的SCSS文件中,如下所示:

@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);
  }

  40% {
    -webkit-transform: scale3d(0.9, 0.9, 0.9);
    transform: scale3d(0.9, 0.9, 0.9);
  }

  60% {
    opacity: 1;
    -webkit-transform: scale3d(1.03, 1.03, 1.03);
    transform: scale3d(1.03, 1.03, 1.03);
  }

  80% {
    -webkit-transform: scale3d(0.97, 0.97, 0.97);
    transform: scale3d(0.97, 0.97, 0.97);
  }

  to {
    opacity: 1;
    -webkit-transform: scale3d(1, 1, 1);
    transform: scale3d(1, 1, 1);
  }
}

我不必这样做。另外,如果我求助于此功能,最好只是卸载Animate.css,然后将我使用的密钥帧复制到我的 global.scss.scss 中?

I'm trying to use animate.css with React/Next.js. I can create animations using animate.css's inline class names, but I want to call animate.css's keyframe animations from my scss file. I was following a youtube guide and he was able to do it. The only difference is that I'm using Next.js.

As a reference:

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

He imports the animate.css file at 3:55 and and is able to use animate.css's bounceIn animation at 38:31.

Example:

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

@import 'animate.css'

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

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

In the same file and inside the React component,

This works for me:

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

But this doesn't:

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

In my AnimatedLetters.module.scss, I have

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

A hacky way of getting by this is finding the keyframe inside the node_modules/animate.css/animate.css file and then copying it into my scss file, like 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);
  }

  40% {
    -webkit-transform: scale3d(0.9, 0.9, 0.9);
    transform: scale3d(0.9, 0.9, 0.9);
  }

  60% {
    opacity: 1;
    -webkit-transform: scale3d(1.03, 1.03, 1.03);
    transform: scale3d(1.03, 1.03, 1.03);
  }

  80% {
    -webkit-transform: scale3d(0.97, 0.97, 0.97);
    transform: scale3d(0.97, 0.97, 0.97);
  }

  to {
    opacity: 1;
    -webkit-transform: scale3d(1, 1, 1);
    transform: scale3d(1, 1, 1);
  }
}

I would prefer not to have to do this. Also, if I do resort to this, would it be best just to uninstall animate.css and just copy the keyframes I'm using into my global.scss?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2025-02-05 22:53:38

由于 bouncein 动画在全球声明(即在 andimate.css 中导入 globals.scs.scss ),因此您必须使用 :Global 选择器在SASS模块文件中使用时。否则,SASS模块假设 Bouncein 是本地范围的,并且将放置动画名称。

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

/* or */

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

默认情况下,CSS模块假定所有内容都是局部范围的。如果要访问全球范围范围的任何内容,则必须使用:Global

Since the bounceIn animation is declared globally (i.e. imported from animate.css in your globals.scss), you have to use the :global selector when using it in your Sass Modules file. Otherwise, Sass Modules assumes bounceIn is locally scoped and will hash the 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 everything is locally scoped. If you want to access anything that's globally scoped you have to use :global.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文