transition.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view>
  3. <uni-card is-full :is-shadow="false">
  4. <text class="uni-h6">过渡动画,通常用于元素的过渡效果,例如淡隐淡出效果,遮罩层的效果、放大缩小的效果等</text>
  5. </uni-card>
  6. <uni-section title="示例" type="line">
  7. <view class="example">
  8. <uni-transition ref="ani" custom-class="transition" :mode-class="modeClass" :styles="styles" :show="show"><text class="text">示例元素</text></uni-transition>
  9. </view>
  10. </uni-section>
  11. <uni-section title="操作" subTitle="点击按钮 ,切换动画效果" type="line">
  12. <view class="example-body">
  13. <button class="transition-button" type="primary" @click="handle('fade')">淡隐淡出</button>
  14. <button class="transition-button" type="primary" @click="handle(['fade', 'slide-top'])">由上至下</button>
  15. <button class="transition-button" type="primary" @click="handle(['fade', 'slide-right'])">由右至左过</button>
  16. <button class="transition-button" type="primary" @click="handle(['fade', 'zoom-in'])">由小到大过</button>
  17. <button class="transition-button" type="primary" @click="custom">自定义动画</button>
  18. </view>
  19. </uni-section>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. components: {},
  25. data() {
  26. return {
  27. show: true,
  28. modeClass: 'fade',
  29. styles: {}
  30. }
  31. },
  32. onLoad() {
  33. // #ifdef APP-NVUE
  34. this.styles = {
  35. justifyContent: 'center',
  36. alignItems: 'center',
  37. width: '100px',
  38. height: '100px',
  39. borderRadius: '5px',
  40. textAlign: 'center',
  41. backgroundColor: '#4cd964',
  42. boxShadow: '0 0 5px 1px rgba(0,0,0,0.2)'
  43. }
  44. // #endif
  45. },
  46. methods: {
  47. handle(type) {
  48. this.show = !this.show
  49. this.modeClass = type
  50. },
  51. custom() {
  52. // TODO 下面修改宽高在百度下还有些问题待修复
  53. // this.$refs.ani.step({
  54. // width: '200px'
  55. // })
  56. // this.$refs.ani.step({
  57. // height: '150px'
  58. // },{
  59. // delay:100,
  60. // duration:200
  61. // })
  62. this.$refs.ani.step(
  63. {
  64. width: '100px',
  65. height: '100px',
  66. rotate: '180'
  67. },
  68. {
  69. delay: 200,
  70. duration: 300
  71. }
  72. )
  73. this.$refs.ani.step(
  74. {
  75. width: '100px',
  76. height: '100px',
  77. rotate: '0'
  78. },
  79. {
  80. transformOrigin: '50% 50%'
  81. }
  82. )
  83. this.$refs.ani.step(
  84. {
  85. translateX: '-100px'
  86. },
  87. {
  88. timingFunction: 'ease-in',
  89. duration: 100
  90. }
  91. )
  92. this.$refs.ani.step(
  93. {
  94. translateX: '100px'
  95. },
  96. {
  97. timingFunction: 'ease',
  98. duration: 300
  99. }
  100. )
  101. this.$refs.ani.step(
  102. {
  103. translateX: '50px',
  104. scale: 1.5
  105. },
  106. {
  107. timingFunction: 'linear',
  108. duration: 100
  109. }
  110. )
  111. this.$refs.ani.step(
  112. {
  113. translateX: '0px',
  114. scale: 1
  115. },
  116. {
  117. timingFunction: 'linear',
  118. duration: 150
  119. }
  120. )
  121. this.$refs.ani.run()
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .example {
  128. /* #ifndef APP-NVUE */
  129. display: flex;
  130. /* #endif */
  131. justify-content: center;
  132. align-items: center;
  133. height: 150px;
  134. background-color: #fff;
  135. }
  136. .example-body {
  137. padding: 10px 20px;
  138. padding-bottom: 0px;
  139. }
  140. .transition-button {
  141. /* #ifndef APP-NVUE */
  142. width: 100%;
  143. /* #endif */
  144. flex: 1;
  145. margin-bottom: 10px;
  146. }
  147. /* #ifndef APP-NVUE */
  148. .example ::v-deep .transition {
  149. display: flex;
  150. justify-content: center;
  151. align-items: center;
  152. width: 100px;
  153. height: 100px;
  154. border-radius: 5px;
  155. text-align: center;
  156. background-color: #4cd964;
  157. box-shadow: 0 0 5px 1px rgba(0, 0, 0, 0.2);
  158. }
  159. /* #endif */
  160. .text {
  161. font-size: 14px;
  162. color: #fff;
  163. }
  164. </style>