
17

80 行代码实现 Preact-Transition 组件
source link: https://github.com/deepkolos/pc-transition
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

pc-transition
一个使用 hooks
编写的transition组件, 主要是之前使用的 preact-transition-group 里的 CSSTransition
组件, 偶现入场动画不触发的情况, 故使用hooks实现了一个
- 接口与CSSTransition类似
- 大概80行代码
- 无需设置duration, duration与transition-duration一样
- 无需繁琐设置classNames传递一个className即可, css里配合data-state来命中状态
Live Demo
Props
参数 类型 默认值 描述 in boolean false 是否过渡到entered appear boolean false 刚创建的时候是否有动画 className string className unmountOnExit number 0.13 滑动到下一页阈值Events
事件名 参数 描述 onEnter 进入前, 相当于vue的enter onEntering 进入中, 相当于vue的enterActive onEntered 进入后, 相当于vue的enterTo onExit 离开前, 相当于vue的leave onExiting 离开中, 相当于vue的leaveActive onExited 离开后, 相当于vue的leaveToDemo Code
function Page() { return <div> <Transition> <div>transition</div> </Transition> </div> }
TODO
- transition-group
- 支持animation
License
MIT 造轮子锻炼抽象能力
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK