为什么我的成帧器运动 h1 组件在我的 React 项目中发生偏移?
P粉391955763
P粉391955763 2024-01-16 16:45:47
0
1
402

所以当我在 h1 上使用成帧器运动时遇到问题

import { motion } from "framer-motion";
function FirstPage() {
  return (
    <motion.h1
      initial={{ opacity: 0, scale: 0.5, y: -100, x: -100 }}
      animate={{ opacity: 1, scale: 1 }}
      transition={{
        duration: 0.8,
        delay: 0.5,
        ease: [0, 0.71, 0.2, 1.01],
      }}
    >
      Tehauto
    </motion.h1>
  );
}

在 css 中,我将 h1 居中,在动画中,我不更改 x 坐标 但由于某种原因它向右偏移 我不知道这是否重要,但我也安装了引导程序

带有成帧器运动(图片链接)

当我使用常规 h1(图片链接)时

我尝试删除整个标题,然后保存并再次重写,但没有成功

P粉391955763
P粉391955763

全部回复(1)
P粉590428357

我尽力解决您的所有问题!!

是否安装了bootstrap并不重要(样式也可以很好地覆盖)。

最主要的是,您需要创建 div 并将其包装起来,并在 h1div 中使用内联样式。 像这样你可以做到:

//...
     <div
        style={{
          height: '0px',
          width: '100px',
          top: '200px',
          color: 'white',
          left: '40%',
          position: 'relative',
        }}
      >
        <motion.h1
          initial={{
            left: -30,
            position: 'relative',
            opacity: 0,
            scale: 0.5,
            y: -100,
          }}
          style={{
            fontSize: '80px',
            visibility: 'visible',
          }}
          animate={{ opacity: 1, scale: 1 }}
          transition={{
            duration: 0.8,
            delay: 0.5,
            ease: [0, 0.71, 0.2, 1.01],
          }}
        >
          Tehauto
        </motion.h1>
      </div>
//...

以下是更新示例链接

你可以乱搞它。

希望这会有所帮助!

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板