简体   繁体   English

如何使用ReactCSStransitionGroup或ReactTransitionGroup在React JS中滑动无状态组件?

[英]How to slide down a stateless component in React JS using ReactCSStransitionGroup or ReactTransitionGroup?

I want to slide a stateless component, which will be initially set to display:none , to be visible after state change in one of its parent component, as if it is slide down just like a dropdown. 我想滑动一个无状态组件,该组件最初将设置为display:none ,以便在其父组件之一的状态更改后可见,就像它像下拉菜单一样向下滑动。 I am new to animation part, I was trying out this_link . 我是动画部分的新手,我正在尝试this_link

So far what i tried in Sandbox ( https://codesandbox.io/s/0xrjp051pp ). 到目前为止,我在沙盒( https://codesandbox.io/s/0xrjp051pp )中尝试过的工作。

Can someone help on this? 有人可以帮忙吗?

Here is the modified Sandbox with the transition working. 这是带有过渡功能的修改后的沙盒。 https://codesandbox.io/s/nrz8vlmrrl The only thing that you need to fix is the CSS code to get it to work a desired. https://codesandbox.io/s/nrz8vlmrrl唯一需要修复的是CSS代码,以使其正常工作。

The changes I made are as follows. 我所做的更改如下。

  1. Changed the transition class in CSS to display the component. 更改了CSS中的过渡类以显示组件。 It had display:none previously. 它没有显示:以前没有。
  2. Show and hide the component based on the prop that you were passing but not using in your component SubComponent . 根据您正在传递但未在组件SubComponent使用的道具来显示和隐藏组件。

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

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