Pengpai-FadeInOut.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view>
  3. <view
  4. ref="ani"
  5. :animation="animationData"
  6. class="message"
  7. :style="{ top: top + 'px', left: left + 'px' }"
  8. v-if="show"
  9. >
  10. <view class="round bg-gradual-orange flex justify-start shadow" style="padding: 3px;">
  11. <view class="cu-avatar cu-a-sm round" :style="{ backgroundImage: `url(${info.touxiang || '/static/images/my/mine_def_touxiang_3x.png'})` }">
  12. <!-- #ifdef APP-NVUE -->
  13. <image :src="info.touxiang || '/static/images/my/mine_def_touxiang_3x.png'" class="avatarimg"></image>
  14. <!-- #endif -->
  15. </view>
  16. <view class="padding-lr-sm flex align-center">
  17. <text class="text-sm">{{ info.content }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. // #ifdef APP-NVUE
  25. const animation = uni.requireNativePlugin('animation');
  26. // #endif
  27. export default {
  28. name: 'Pengpai-FadeInOut',
  29. props: {
  30. //持续时间
  31. duration: {
  32. type: Number,
  33. default: 2600
  34. },
  35. //停留时间
  36. wait: {
  37. type: Number,
  38. default: 3000
  39. },
  40. //顶部距离px
  41. top: {
  42. type: Number,
  43. default: 160
  44. },
  45. //左边距离px
  46. left: {
  47. type: Number,
  48. default: 10
  49. },
  50. //动画半径
  51. radius: {
  52. type: Number,
  53. default: 30
  54. },
  55. //数据
  56. info: {
  57. type: [Array,Object],
  58. default: () => {
  59. return []
  60. }
  61. }
  62. },
  63. data() {
  64. return {
  65. animationData: {},
  66. animationNumber:{},
  67. show: true
  68. };
  69. },
  70. mounted(){
  71. this.donghua();
  72. },
  73. watch:{
  74. },
  75. methods: {
  76. donghua() {
  77. //进入
  78. // #ifndef APP-NVUE
  79. this.animationData = uni
  80. .createAnimation({
  81. duration: this.duration / 2,
  82. timingFunction: 'ease'
  83. })
  84. .top(this.top - this.radius)
  85. .opacity(0.9)
  86. .step()
  87. .export();
  88. // #endif
  89. // #ifdef APP-NVUE
  90. if (!this.$refs['ani']) return;
  91. animation.transition(
  92. this.$refs['ani'].ref,
  93. {
  94. styles: {
  95. transform: `translateY(-${this.radius/2}px)`,
  96. opacity: 1
  97. },
  98. duration: this.duration/2,
  99. timingFunction: 'linear',
  100. needLayout: false,
  101. delay: 0
  102. }
  103. );
  104. // #endif
  105. //停留
  106. setTimeout(() => {
  107. //消失
  108. // #ifndef APP-NVUE
  109. this.animationData = uni
  110. .createAnimation({
  111. duration: this.duration / 2,
  112. timingFunction: 'ease'
  113. })
  114. .top(this.top - this.radius * 2)
  115. .opacity(0)
  116. .step()
  117. .export();
  118. // #endif
  119. // #ifdef APP-NVUE
  120. if (!this.$refs['ani']) return;
  121. animation.transition(
  122. this.$refs['ani'].ref,
  123. {
  124. styles: {
  125. transform: `translateY(-${this.radius}px)`,
  126. opacity: 0
  127. },
  128. duration: this.duration/2,
  129. timingFunction: 'linear',
  130. needLayout: false,
  131. delay: 0
  132. }
  133. );
  134. // #endif
  135. }, this.wait);
  136. }
  137. }
  138. };
  139. </script>
  140. <style scoped>
  141. .message {
  142. position: fixed;
  143. z-index: 99999;
  144. opacity: 9;
  145. }
  146. .round {
  147. border-radius: 5000px;
  148. }
  149. .bg-gradual-orange {
  150. /* #ifndef APP-NVUE */
  151. background-image: linear-gradient(45deg, #222222, #333333);
  152. /* #endif */
  153. /* #ifdef APP-NVUE */
  154. background-image: linear-gradient(to bottom right, #222222, #333333);
  155. /* #endif */
  156. color: #ffffff;
  157. }
  158. .shadow {
  159. box-shadow: 4px 4px 5px rgba(217, 109, 26, 0.2);
  160. }
  161. .flex {
  162. /* #ifndef APP-NVUE */
  163. display: flex;
  164. /* #endif */
  165. flex-direction: row;
  166. }
  167. .justify-start {
  168. justify-content: flex-start;
  169. }
  170. .cu-avatar {
  171. /* #ifndef APP-NVUE */
  172. font-variant: small-caps;
  173. display: inline-flex;
  174. white-space: nowrap;
  175. background-size: cover;
  176. background-position: center;
  177. vertical-align: middle;
  178. /* #endif */
  179. margin: 0;
  180. padding: 0;
  181. text-align: center;
  182. justify-content: center;
  183. align-items: center;
  184. background-color: #ccc;
  185. color: #ffffff;
  186. position: relative;
  187. width: 20px;
  188. height: 20px;
  189. font-size: 1.5em;
  190. }
  191. /* #ifdef APP-NVUE */
  192. .avatarimg {
  193. width: 20px;
  194. height: 20px;
  195. border-radius: 50px;
  196. }
  197. /* #endif */
  198. .cu-a-sm {
  199. width: 20px;
  200. height: 20px;
  201. font-size: 0.8em;
  202. }
  203. .padding-lr-sm {
  204. padding-left: 20upx;
  205. padding-right: 20upx;
  206. }
  207. .align-center {
  208. align-items: center;
  209. }
  210. .margin-left-xs {
  211. margin-left: 10upx;
  212. }
  213. .text-bold {
  214. font-weight: bold;
  215. }
  216. .margin-lr-sm {
  217. margin-left: 20upx;
  218. margin-right: 20upx;
  219. }
  220. .text-sm {
  221. font-size: 12px;
  222. color: #ffffff;
  223. }
  224. </style>