AnimationGroup 动画组

将自定义的组件包裹在 animation-group 组件内,可以实现过渡/动画效果,预设 9 种过渡效果 fadeIn, fadeInDown, fadeInLeft, fadeInRight, fadeInUp, slideInUp, slideInDown, slideInLeft, slideInRight, zoom, punch 可选用。

在进入/离开的过渡中,会有 6 个 class 切换:

  • -enter: 进入过渡的开始状态,在过渡过程完成之后移除
  • -enter-active: 进入过渡的结束状态,在过渡过程完成之后移除
  • -enter-done: 进入过渡的完成状态
  • -exit: 离开过渡的开始状态,在过渡过程完成之后移除
  • -exit-active: 离开过渡的结束状态,在过渡过程完成之后移除
  • -exit-done: 离开过渡的完成状态

使用指南

在 page.json 中引入组件

  1. {
  2. "navigationBarTitleText": "AnimationGroup",
  3. "usingComponents": {
  4. "wux-animation-group": "../../dist/animation-group/index"
  5. }
  6. }

示例

  1. <view class="page">
  2. <view class="page__hd">
  3. <view class="page__title">AnimationGroup</view>
  4. <view class="page__desc">动画组</view>
  5. </view>
  6. <view class="page__bd">
  7. <view class="weui-cells weui-cells_after-title">
  8. <view class="weui-cell weui-cell_select">
  9. <view class="weui-cell__hd weui-cell__hd_in-select-after">
  10. <view class="weui-label" style="width: auto;">Switch classNames</view>
  11. </view>
  12. <view class="weui-cell__bd">
  13. <picker bindchange="pickerChange" value="{{ index }}" range="{{ items }}">
  14. <view class="weui-select weui-select_in-select-after" style="padding-left: 30px;">{{ items[index] }}</view>
  15. </picker>
  16. </view>
  17. </view>
  18. <view class="weui-cell weui-cell_switch">
  19. <view class="weui-cell__bd">Enable or disable enter transitions</view>
  20. <view class="weui-cell__ft">
  21. <switch data-model="example.enter" bindchange="switchChange" checked="{{ example.enter }}" />
  22. </view>
  23. </view>
  24. <view class="weui-cell weui-cell_switch">
  25. <view class="weui-cell__bd">Enable or disable exit transitions</view>
  26. <view class="weui-cell__ft">
  27. <switch data-model="example.exit" bindchange="switchChange" checked="{{ example.exit }}" />
  28. </view>
  29. </view>
  30. <view class="weui-cell weui-cell_switch">
  31. <view class="weui-cell__bd">Switch state</view>
  32. <view class="weui-cell__ft">
  33. <switch data-model="example.in" bindchange="switchChange" checked="{{ example.in }}" />
  34. </view>
  35. </view>
  36. <view class="weui-cell weui-cell_switch">
  37. <view class="weui-cell__bd">Toggle</view>
  38. <view class="weui-cell__ft">
  39. <switch bindchange="onToggle" checked="{{ show }}" />
  40. </view>
  41. </view>
  42. </view>
  43. <wux-animation-group wux-class="example" in="{{ example.in }}" enter="{{ example.enter }}" exit="{{ example.exit }}" class-names="{{ example.classNames }}" bind:click="onClick" bind:enter="onEnter" bind:entering="onEntering" bind:entered="onEntered" bind:exit="onExit"
  44. bind:exiting="onExiting" bind:exited="onExited">
  45. <view class="weui-article">
  46. <view class="weui-article__p">
  47. 微信小程序自定义组件 https://github.com/wux-weapp/wux-weapp
  48. </view>
  49. </view>
  50. </wux-animation-group>
  51. <wux-animation-group wux-class="example" in="{{ show }}" duration="{{ 1000 }}" unmountOnExit="{{ false }}" bind:change="onChange">
  52. <view class="weui-article">
  53. <view class="weui-article__p">{{ status }}</view>
  54. </view>
  55. </wux-animation-group>
  56. </view>
  57. </view>
  1. Page({
  2. data: {
  3. items: [
  4. 'fadeIn',
  5. 'fadeInDown',
  6. 'fadeInLeft',
  7. 'fadeInRight',
  8. 'fadeInUp',
  9. 'slideInUp',
  10. 'slideInDown',
  11. 'slideInLeft',
  12. 'slideInRight',
  13. 'zoom',
  14. 'punch',
  15. ],
  16. index: 0,
  17. example: {
  18. classNames: 'wux-animate--fadeIn',
  19. enter: true,
  20. exit: true,
  21. in: false,
  22. },
  23. show: false,
  24. status: '',
  25. },
  26. pickerChange(e) {
  27. const index = e.detail.value
  28. const value = this.data.items[index]
  29. const classNames = `wux-animate--${value}`
  30. this.setData({
  31. index,
  32. 'example.classNames': classNames,
  33. })
  34. },
  35. switchChange(e) {
  36. const { model } = e.currentTarget.dataset
  37. this.setData({
  38. [model]: e.detail.value,
  39. })
  40. },
  41. onClick() { console.log('onClick') },
  42. onEnter(e) { console.log('onEnter', e.detail) },
  43. onEntering(e) { console.log('onEntering', e.detail) },
  44. onEntered(e) { console.log('onEntered', e.detail) },
  45. onExit() { console.log('onExit') },
  46. onExiting() { console.log('onExiting') },
  47. onExited() { console.log('onExited') },
  48. onToggle() {
  49. this.setData({
  50. show: !this.data.show,
  51. })
  52. },
  53. onChange(e) {
  54. const { animateStatus } = e.detail
  55. switch (animateStatus) {
  56. case 'entering':
  57. this.setData({ status: 'Entering…' })
  58. break
  59. case 'entered':
  60. this.setData({ status: 'Entered!' })
  61. break
  62. case 'exiting':
  63. this.setData({ status: 'Exiting…' })
  64. break
  65. case 'exited':
  66. this.setData({ status: 'Exited!' })
  67. break
  68. }
  69. },
  70. })

视频演示

AnimationGroup

API

AnimationGroup props

参数 类型 描述 默认值
in boolean 触发组件进入或离开过渡的状态 false
classNames any 过渡的类名 -
duration any 过渡持续时间 -
type string 过渡动效的类型 transition
appear boolean 首次挂载时是否触发进入过渡 false
enter boolean 是否启用进入过渡 true
exit boolean 是否启用离开过渡 true
mountOnEnter boolean 首次进入过渡时是否懒挂载组件 true
unmountOnExit boolean 离开过渡完成时是否卸载组件 true
wrapCls string 自定义类名 -
wrapStyle string,object 自定义样式 -
disableScroll boolean 阻止移动触摸 false
bind:click function 点击组件时触发的回调函数 -
bind:enter function 进入过渡的开始状态时触发的回调函数 -
bind:entering function 进入过渡的结束状态时触发的回调函数 -
bind:entered function 进入过渡的完成状态时触发的回调函数 -
bind:exit function 离开过渡的开始状态时触发的回调函数 -
bind:exiting function 离开过渡的结束状态时触发的回调函数 -
bind:exited function 离开过渡的完成状态时触发的回调函数 -
bind:change function 监听状态变化的回调函数 -

AnimationGroup slot

名称 描述
- 自定义内容

AnimationGroup externalClasses

名称 描述
wux-class 根节点样式类