简体   繁体   English

尝试使用 Framer-motion motion.div 为轮播设置动画

[英]Trying to animate a carousel with Framer-motion motion.div

I am trying to animate a carousel transition with Framer-motion motion.div, I am doing some reading but haven't made much progress as this is my first time using animations.我正在尝试使用 Framer-motion motion.div 为轮播动画制作动画,我正在阅读但没有取得太大进展,因为这是我第一次使用动画。 If anyone could point my in the right direction I would be very grateful, I basically have a piece of state linked to my pagination that sets the scroll direction on the animation to either "left" or "right".如果有人能指出我正确的方向,我将不胜感激,我基本上有一块 state 链接到我的分页,它将 animation 上的滚动方向设置为“左”或“右”。 i really just need to figure out a way to set the enter and exit animation on my motion.div using this right or left from state.我真的只需要想办法在我的motion.div上使用state的右边或左边设置进入和退出animation。 I could change the state to have any value really.我可以将 state 更改为真正具有任何价值。

I guess what Im confused about, is i'm currently showing the cards in my table as a Stack of items, and when I paginate, the stack changes, the cards currently shown change to the next set in the data object.我想我感到困惑的是,我目前将表格中的卡片显示为一堆项目,当我分页时,堆栈发生变化,当前显示的卡片更改为数据 object 中的下一组。 I suppose Im not understanding how to animate the entrance and exit of one div as its changing?我想我不明白如何为一个 div 的入口和出口设置动画作为它的变化? Im continuing to read about animations but am in a real hurry to get this done.我继续阅读有关动画的内容,但我真的很急于完成这项工作。

heres what I put together:这是我放在一起的:

  <AnimatePresence exitBeforeEnter>
          <motion.div animate={{ x: { ???? } }}
            style={{ position: 'absolute' }}>
              <HStack spacing={6}>
                {data.objectives.edges.map(e => (
                  <ObjectiveCard
                    objective={e.node}
                    key={e.node.id}
                    completeObjective={completeObjective}
                  />
                ))}
              </HStack>
          </motion.div> 
        </AnimatePresence>

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

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