简体   繁体   English

仅在成帧运动中的动画期间应用样式

[英]Apply styles only during animation in framer-motion

I have a collapsible panels animated with framer motion.我有一个带有成帧器动作的可折叠面板。 When the panel switches from collapsed to open the overflow is visible.当面板从折叠切换到打开时,溢出是可见的。 This breaks the layout somewhat as the content of the panel body then overlays the content below.这会在一定程度上破坏布局,因为面板主体的内容会覆盖下面的内容。 However, I need the overflow to properly display a dropdown list inside the panels.但是,我需要溢出才能在面板内正确显示下拉列表。

在此处输入图像描述

I came up with the following idea.我想出了以下想法。

Basically I want to apply "overflow:hidden" to the StyledPanelBody when the framer animation is being executed.基本上我想在执行成帧动画时将“溢出:隐藏”应用于 StyledPanelBody。 This would prevent the ugly effect with the overlay.这将防止覆盖层的丑陋效果。 However, I couldn't find any way to do that from the documentation.但是,我无法从文档中找到任何方法来做到这一点。 There is just a "transitionEnd" property.只有一个“transitionEnd”属性。

const PanelBody = ({children, isFramed, isOpen}) => {
  const currentVariant = isOpen ? 'open' : 'closed'

  const loadFeatures = () =>
    import('./framerMotionFeatures.js').then(res => res.default)

  return (
    <LazyMotion features={loadFeatures}>
    <StyledPanelBody
      initial={currentVariant}
      animate={currentVariant}
      variants={{
        closed: {height: 0},
        open: {height: 'auto'}
      }}
      transition={{ease: 'easeInOut', duration: 0.3}}
      isFramed={isFramed}
      isOpen={isOpen}
    >
      <div>
        {children}
      </div>
    </StyledPanelBody>
    </LazyMotion>
  )
}

You can try this as a workaround:您可以尝试将此作为解决方法:

variants={{
  closed: {
    height: 0,
    overflow: 'hidden',
  },
  open: {
    height: 'auto',
    transitionEnd: {
      overflow: 'unset',
    }
  }
}}

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

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