首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何启动框架运动?

如何启动框架运动?
EN

Stack Overflow用户
提问于 2021-02-12 08:47:29
回答 1查看 66关注 0票数 0
代码语言:javascript
复制
  I tried to make a modal window but I couldn't do it since framer doesn't work. I tried to use animate={{color: "red"}} and it worked but without animations, the text just became red;

Belowe,你可以看到将模型从顶部移动到几乎中心的代码。

代码语言:javascript
复制
import {motion} from 'framer-motion'

const modal = {
  hidden: {
    y: "-100vh",
    opacity: 0,
  },
  visible: {
    y: "200px",
    opacity: 1,
    transition: {delay: 0.5}
  }
}

<motion.div className="error-pop-up" variants={modal}>
  {error}
</motion.div>


It should go from top to almost center or something but it just doesn't do anything. I installed framer using yarn.
EN

回答 1

Stack Overflow用户

发布于 2021-02-14 08:17:32

在运动组件中,必须指定将哪个变量指定给初始道具和设置道具动画。

代码语言:javascript
复制
<motion.div className="error-pop-up" variants={modal} initial="hidden" animate="visible">
  {error}
</motion.div>

对于情态类型,我通常会声明一个useState,并将其与一个三元运算符组合在一起,如下所示:

const [modalOpen, setModalOpen] = useState(false)

代码语言:javascript
复制
<motion.div className="error-pop-up" variants={modal} initial="hidden" animate={modalOpen ? "visible" : "hidden"}>
  {error}
</motion.div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66165056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档