Framer Motion的动画在移动端卡顿怎么办?
我在用Framer Motion做下拉刷新动画时,iOS设备滑动特别卡顿。用了animatePresence和stagger,代码大致是这样的:
const container = useMotionValue(0);
const springConfig = { damping: 30, stiffness: 200 };
function onRefresh() {
// 数据加载逻辑
}
return (
<MotionViewport>
<motion.div
drag="y"
dragConstraints={{ max: 100 }}
style={{ y: container }}
whileDrag={{ originY: 'start' }}
transition={springConfig}
onDragEnd={(e, { velocity }) => {
if (container.get() > 60) onRefresh();
}}
>
{/* 列表内容 */}
</motion.div>
</MotionViewport>
);
尝试过把layoutEffect设为false和调整framerate都不管用,有经验的同学遇到过类似问题吗?
drag换成panGesture手动控制,避免Framer Motion内部的性能开销:实在不行就直接用原生CSS动画或者requestAnimationFrame自己写滑动逻辑,别让库拖后腿。