transition.nvue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view>
  3. <text class="example-info">过渡动画,通常用于元素的过渡效果,例如淡隐淡出效果,遮罩层的效果、放大缩小的效果等</text>
  4. <uni-section title="基础过渡动画" type="line"></uni-section>
  5. <view class="example-body">
  6. <button class="transition-button" type="primary" @click="open(['fade'])">fade</button>
  7. <button class="transition-button" type="primary" @click="open(['slide-top'])">slide-top</button>
  8. <button class="transition-button" type="primary" @click="open(['slide-left'])">slide-left</button>
  9. <button class="transition-button" type="primary" @click="open(['slide-right'])">slide-right</button>
  10. <button class="transition-button" type="primary" @click="open(['slide-bottom'])">slide-bottom</button>
  11. <button class="transition-button" type="primary" @click="open(['zoom-in','fade'])">zoom-in</button>
  12. <button class="transition-button" type="primary" @click="open(['zoom-out','fade'])">zoom-out</button>
  13. </view>
  14. <uni-section title="组合过渡动画" type="line"></uni-section>
  15. <view class="example-body">
  16. <button class="transition-button" type="primary" @click="mask">透明遮罩层</button>
  17. <button class="transition-button" type="primary" @click="open(['fade','zoom-out','slide-top'])">组合动画示例一</button>
  18. <button class="transition-button" type="primary" @click="open(['zoom-in','slide-bottom','fade'])">组合动画示例二</button>
  19. <button class="transition-button" type="primary" @click="open(['slide-left','slide-top','fade'])">组合动画示例三</button>
  20. </view>
  21. <!-- 遮罩 -->
  22. <uni-transition :mode-class="['fade']" :styles="maskClass" :show="show" @click="onTap" />
  23. <!-- 过渡 -->
  24. <uni-transition :duration="500" :mode-class="modeClass" :styles="transfromClass" :show="transShow" @click="onTap" @change="change">
  25. <text class="box">Test</text>
  26. </uni-transition>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. components: {},
  32. data() {
  33. return {
  34. show: false,
  35. transShow: false,
  36. modeClass: ['fade'],
  37. maskClass: {
  38. 'position': 'fixed',
  39. 'bottom': 0,
  40. 'top': 0,
  41. 'left': 0,
  42. 'right': 0,
  43. 'background-color': 'rgba(0, 0, 0, 0.4)'
  44. },
  45. transfromClass: {
  46. 'position': 'fixed',
  47. 'bottom': 0,
  48. 'top': 0,
  49. 'left': 0,
  50. 'right': 0,
  51. /* #ifndef APP-NVUE */
  52. 'display': 'flex',
  53. /* #endif */
  54. 'justify-content': 'center',
  55. 'align-items': 'center'
  56. }
  57. }
  58. },
  59. onLoad() {},
  60. methods: {
  61. mask() {
  62. this.show = true
  63. },
  64. open(mode) {
  65. this.modeClass = mode
  66. this.transShow = !this.transShow
  67. },
  68. onTap() {
  69. this.transShow = this.show = false
  70. },
  71. change(e) {
  72. console.log(e.detail);
  73. }
  74. }
  75. }
  76. </script>
  77. <style>
  78. @charset "UTF-8";
  79. /* 头条小程序组件内不能引入字体 */
  80. /* #ifdef MP-TOUTIAO */
  81. @font-face {
  82. font-family: uniicons;
  83. font-weight: normal;
  84. font-style: normal;
  85. src: url("~@/static/uni.ttf") format("truetype");
  86. }
  87. /* #endif */
  88. /* #ifndef APP-NVUE */
  89. page {
  90. display: flex;
  91. flex-direction: column;
  92. box-sizing: border-box;
  93. background-color: #efeff4;
  94. min-height: 100%;
  95. height: auto;
  96. }
  97. view {
  98. font-size: 14px;
  99. line-height: inherit;
  100. }
  101. .example {
  102. padding: 0 15px 15px;
  103. }
  104. .example-info {
  105. padding: 15px;
  106. color: #3b4144;
  107. background: #ffffff;
  108. }
  109. .example-body {
  110. /* #ifndef APP-NVUE */
  111. display: flex;
  112. /* #endif */
  113. flex-direction: row;
  114. flex-wrap: wrap;
  115. justify-content: center;
  116. padding: 0;
  117. font-size: 14px;
  118. background-color: #ffffff;
  119. }
  120. /* #endif */
  121. .example {
  122. padding: 0 15px;
  123. }
  124. .example-info {
  125. /* #ifndef APP-NVUE */
  126. display: block;
  127. /* #endif */
  128. padding: 15px;
  129. color: #3b4144;
  130. background-color: #ffffff;
  131. font-size: 14px;
  132. line-height: 20px;
  133. }
  134. .example-info-text {
  135. font-size: 14px;
  136. line-height: 20px;
  137. color: #3b4144;
  138. }
  139. .example-body {
  140. flex-direction: column;
  141. padding: 15px;
  142. background-color: #ffffff;
  143. }
  144. .word-btn-white {
  145. font-size: 18px;
  146. color: #FFFFFF;
  147. }
  148. .word-btn {
  149. /* #ifndef APP-NVUE */
  150. display: flex;
  151. /* #endif */
  152. flex-direction: row;
  153. align-items: center;
  154. justify-content: center;
  155. border-radius: 6px;
  156. height: 48px;
  157. margin: 15px;
  158. background-color: #007AFF;
  159. }
  160. .word-btn--hover {
  161. background-color: #4ca2ff;
  162. }
  163. .example-body {
  164. padding: 15px 20px;
  165. /* #ifndef APP-NVUE */
  166. display: flex;
  167. /* #endif */
  168. flex-direction: row;
  169. flex-wrap: wrap;
  170. justify-content: flex-start;
  171. }
  172. .transition-button {
  173. /* #ifndef APP-NVUE */
  174. /* width: 100%; */
  175. /* #endif */
  176. padding: 0 15px;
  177. margin: 10px 5px;
  178. }
  179. .box {
  180. color: #fff;
  181. width: 100px;
  182. height: 100px;
  183. line-height: 100px;
  184. text-align: center;
  185. background-color: #4CD964;
  186. }
  187. </style>