简体   繁体   English

在成帧器运动中为 scaleX 设置动画而不影响儿童的比例

[英]animate scaleX in framer motion without affecting children's scale

Framer motion 4 has depreciated useInvertedScale() It says to use the layout prop instead but it doesn't seem to achieve the same effect. Framer motion 4 已贬值useInvertedScale()它说要使用布局道具,但似乎没有达到相同的效果。 I'm trying to scaleX a parent div whiteout affecting the scale of the children.我正在尝试对影响子级规模的父级 div 进行缩放。 There is more going on in my animation but this is a simple breakdown parent scalesX but children should not scale.我的 animation 中还有更多内容,但这是一个简单的故障父 scalesX 但孩子不应该缩放。

    const parentVarent= {
      show: {
        scaleX: 1,
        transition: {
          ease: "easeOut",
          duration: 3,
        },
      },
      hide: {
        scaleX: 0,
      },
    };

const MyComponent = () => {
 return (
    <motion.div
      animate="show"
      variants={parentVarent}
      initial="hide"
    >
      <motion.div variants={parentVarent} layout>
        <p>
          SOME TEXT TO NOT SACLE
        </p>
      </motion.div>
    </motion.div>
 );
};

Ok so after a discussion on the framer-motion discord: You can't use variants or the animate prop.好的,在讨论了成帧运动 discord 之后:您不能使用变体或动画道具。

    <Container
        style={{
          width: isBig ? "100%" : "0%",
          borderRadius: "15px"
        }}
        layout
      >
        <Text />
      </Container>

you have to use style tag or CSS instead.您必须改用样式标签或 CSS 。 Additionally, the layout prop isn't a stand-in replacement.此外,布局道具不是替代品。 It looks like you can't get the width all the way to zero, and the layout is more of a "from one size to another" utility.看起来您无法将宽度一直为零,并且布局更像是“从一种尺寸到另一种尺寸”的实用程序。 If you remove the padding in my v4 example it no longer works:/如果您在我的 v4 示例中删除填充,它将不再起作用:/

For reference:以供参考:

Discord Link: https://discord.com/channels/341919693348536320/716908973713784904/842083550990958642 Discord 链接: https://discord.com/channels/341919693348536320/716908973713784904/84284835509909

This came up in a Github issue here: https://github.com/framer/motion/issues/1145这出现在 Github 问题中: https://github.com/framer/motion/issues/1145

I created a working version in v2 that uses useInvertedScale() : https://codesandbox.io/s/framer-motion-layout-scaling-text-in-framer-motion-295-useinvertedscale-ixqln我在 v2 中创建了一个使用useInvertedScale()的工作版本: https://codesandbox.io/s/framer-motion-layout-scaling-text-in-framer-motion-295-useinvertedscale-ixqln

I created a working version in v4 that doesn't here: https://codesandbox.io/s/framer-motion-layout-scaling-text-in-framer-motion-4-70eb3我在 v4 中创建了一个在这里没有的工作版本: https://codesandbox.io/s/framer-motion-layout-scaling-text-in-framer-motion-4-70eb3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM