transition.nvue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="u-page">
  3. <up-gap height="20" bgColor="#fff"></up-gap>
  4. <up-cell-group border>
  5. <up-cell
  6. :titleStyle="{ fontWeight: 500 }"
  7. @click="openTransition(item.mode)"
  8. :title="item.title"
  9. v-for="(item, index) in list"
  10. :key="index"
  11. clickable
  12. >
  13. <template #icon>
  14. <image
  15. class="u-cell-icon"
  16. :src="item.iconUrl"
  17. mode="widthFix"
  18. ></image>
  19. </template>
  20. </up-cell>
  21. <up-transition
  22. :mode="mode"
  23. :show="show"
  24. :custom-style="style"
  25. @click="click"
  26. @beforeEnter="beforeEnter"
  27. @enter="enter"
  28. @afterEnter="afterEnter"
  29. @beforeLeave="beforeLeave"
  30. @leave="leave"
  31. @afterLeave="afterLeave"
  32. >
  33. <view class="transition"></view>
  34. </up-transition>
  35. </up-cell-group>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. mode: "",
  43. show: false,
  44. style: {
  45. position: "fixed",
  46. top: `${uni.$u.sys().windowHeight / 2 - 50}px`,
  47. left: `${uni.$u.sys().windowWidth / 2 - 50}px`,
  48. width: "120px",
  49. height: "120px",
  50. backgroundColor: "#1989fa",
  51. },
  52. list: [
  53. {
  54. mode: "fade",
  55. title: "淡入",
  56. iconUrl:
  57. "https://cdn.uviewui.com/uview/demo/transition/fade.png",
  58. },
  59. {
  60. mode: "fade-up",
  61. title: "上滑淡入",
  62. iconUrl:
  63. "https://cdn.uviewui.com/uview/demo/transition/fadeUp.png",
  64. },
  65. {
  66. mode: "zoom",
  67. title: "缩放",
  68. iconUrl:
  69. "https://cdn.uviewui.com/uview/demo/transition/zoom.png",
  70. },
  71. {
  72. mode: "fade-zoom",
  73. title: "缩放淡入",
  74. iconUrl:
  75. "https://cdn.uviewui.com/uview/demo/transition/fadeZoom.png",
  76. },
  77. {
  78. mode: "fade-down",
  79. title: "下滑淡入",
  80. iconUrl:
  81. "https://cdn.uviewui.com/uview/demo/transition/fadeDown.png",
  82. },
  83. {
  84. mode: "fade-left",
  85. title: "左滑淡入",
  86. iconUrl:
  87. "https://cdn.uviewui.com/uview/demo/transition/fadeLeft.png",
  88. },
  89. {
  90. mode: "fade-right",
  91. title: "右滑淡入",
  92. iconUrl:
  93. "https://cdn.uviewui.com/uview/demo/transition/fadeRight.png",
  94. },
  95. {
  96. mode: "slide-up",
  97. title: "上滑进入",
  98. iconUrl:
  99. "https://cdn.uviewui.com/uview/demo/transition/slideUp.png",
  100. },
  101. {
  102. mode: "slide-down",
  103. title: "下滑进入",
  104. iconUrl:
  105. "https://cdn.uviewui.com/uview/demo/transition/slideDown.png",
  106. },
  107. {
  108. mode: "slide-left",
  109. title: "左滑进入",
  110. iconUrl:
  111. "https://cdn.uviewui.com/uview/demo/transition/slideLeft.png",
  112. },
  113. {
  114. mode: "slide-right",
  115. title: "右滑进入",
  116. iconUrl:
  117. "https://cdn.uviewui.com/uview/demo/transition/slideRight.png",
  118. },
  119. ],
  120. };
  121. },
  122. mixins: [uni.$u.mixin],
  123. methods: {
  124. openTransition(mode) {
  125. this.mode = mode;
  126. this.show = true;
  127. setTimeout(() => {
  128. this.show = false;
  129. }, 1500);
  130. },
  131. click() {
  132. // console.log("click");
  133. },
  134. beforeEnter() {
  135. // console.log("beforeEnter");
  136. },
  137. enter() {
  138. // console.log("enter");
  139. },
  140. afterEnter() {
  141. // console.log("afterEnter");
  142. },
  143. beforeLeave() {
  144. // console.log("beforeLeave");
  145. },
  146. leave() {
  147. // console.log("leave");
  148. },
  149. afterLeave() {
  150. // console.log("afterLeave");
  151. },
  152. },
  153. };
  154. </script>
  155. <style lang="scss">
  156. .u-page {
  157. padding: 0;
  158. }
  159. .transition {
  160. background-color: $u-primary;
  161. }
  162. </style>