【发布时间】:2022-01-05 12:44:20
【问题描述】:
import React, { useState, useEffect } from "react";
import { motion } from "framer-motion";
import { colors } from "./components/Animations";
export const tick_cross_animation = {
hidden: {
opacity: 0,
pathLength: 0,
},
show: {
opacity: 1,
pathLength: 1,
transition: { duration: 1.25 },
},
};
const Work = ({ check, setcheck, cross, setcross }) => {
const [circle_Check, setcircle_Check] = useState(Infinity);
const circleanimation = {
hidden: {
opacity: 0,
pathLength: 0,
translateX: 5,
translateY: 5,
rotate: -180,
},
show: {
opacity: 1,
pathLength: 1,
transition: {
duration: 1.5,
yoyo: circle_Check,
},
},
};
setTimeout(() => {
setcheck(true);
}, 1250);
useEffect(() => {
if (check || cross === true) {
setcircle_Check(0);
} else {
setcircle_Check(Infinity);
}
console.log(
"Here it is changing but not " + circle_Check
);
}, [check, cross]);
setTimeout(() => {
setcross(true);
}, 3000);
return (
<div
className="wow"
style={{
width: "80%",
margin: "auto",
height: "20rem",
}}
>
<svg className="progress-icon" viewBox="0 0 200 200">
<motion.path
fill="none"
strokeWidth="2"
stroke={colors.color_circle}
d="M 0, 20 a 20, 20 0 1,0 40,0 a 20, 20 0 1,0 -40,0"
variants={circleanimation}
initial="hidden"
animate="show"
/>
{check && (
<motion.path
fill="none"
strokeWidth="2"
stroke={colors.color_tick}
d="M14,26 L 22,33 L 35,16"
variants={tick_cross_animation}
initial="hidden"
animate="show"
/>
)}
{cross && (
<motion.path
fill="none"
strokeWidth="2"
stroke={colors.color_X}
d="M17,17 L33,33 M33,17 L17,33"
variants={tick_cross_animation}
initial="hidden"
animate="show"
/>
)}
</svg>
</div>
);
};
export default Work;
这需要与 show 属性中的 circleanimation同步。 我正在使用 2 个 useStates 来检查和 1 个 useEffect。现在,当 useEffect 运行代码时会更改值,但 yoyo 效果会无限期地继续发生。我希望它与动画一起工作,这样它就不会像 possibel 那样持续太久。 The values do change
【问题讨论】:
标签: javascript reactjs react-hooks use-effect framer-motion