refresh.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class='refreshBox' :style="isTranform">
  3. <view class='refresh' :style="isZoom" :class="isEnd==2?'animationSmall':''">
  4. <view class='refreshWord' v-if="isEnd == 0">松开刷新</view>
  5. <view class='refreshCirle animation' v-if="isEnd == 1"></view>
  6. <image class='iconYes' src='../static/icon-yes.png' v-if="isEnd==2"></image>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'refresh',
  14. props: {
  15. isTop:{
  16. type:Number,
  17. default:1
  18. }
  19. },
  20. data() {
  21. return {
  22. isTranf: 0,
  23. touchStart: '',
  24. touchMove: '',
  25. isEnd: 0
  26. };
  27. },
  28. methods: {
  29. refreshStart(e) {
  30. if (this.isEnd == 0 && this.isTop == 1) {
  31. this.touchStart = e.changedTouches[0].pageY
  32. }
  33. },
  34. refreshMove(e){
  35. if (this.isEnd == 0 && this.isTop == 1) {
  36. var touchStart = this.touchStart,
  37. oldMove = this.touchMove,
  38. newMove = e.changedTouches[0].pageY
  39. if (touchStart <= newMove) {
  40. var isTranf = touchStart > newMove ? 0 : newMove - touchStart
  41. this.isTranf = isTranf
  42. this.touchMove = e.changedTouches[0].pageY
  43. }
  44. } else{
  45. this.isTranf = 0
  46. this.isEnd = 0
  47. this.touchStart = 9999
  48. }
  49. },
  50. refreshEnd(e) {
  51. var that = this
  52. if (this.isEnd == 0 && this.isTop == 1) {
  53. if (this.isTranf >= 90) {
  54. this.isTranf = 125
  55. this.isEnd = 1
  56. this.$emit('isRefresh');
  57. } else {
  58. this.isTranf = 0
  59. }
  60. }
  61. },
  62. endAfter(){
  63. this.isEnd = 2
  64. setTimeout(() => {
  65. this.isTranf = 0
  66. this.isEnd = 0
  67. }, 600)
  68. }
  69. },
  70. computed: {
  71. isTranform() {
  72. var isTranf = this.isTranf > 150 ? 150 : this.isTranf
  73. var isTemp = `transform: translateY(${isTranf-100}px);`
  74. return isTemp
  75. },
  76. isZoom() {
  77. var isTranf = this.isTranf > 125 ? 125 : this.isTranf
  78. var isTemp = `zoom:${isTranf/125};`
  79. return isTemp
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .refreshBox {
  86. margin:0 auto;
  87. width: 100%;
  88. height: 100upx;
  89. overflow: hidden;
  90. display: flex;
  91. align-items: center;
  92. justify-content: center;
  93. max-height: 300upx;
  94. position: fixed;
  95. z-index: 999;
  96. top: 0;
  97. left: 0;
  98. transform: translateY(-100upx);
  99. }
  100. .animationSmall {
  101. animation: small 1.1s both;
  102. }
  103. @keyframes small {
  104. 0% {
  105. transform: scale(1)
  106. }
  107. 20%{
  108. transform: scale(1.4)
  109. }
  110. 100% {
  111. transform: scale(0)
  112. }
  113. }
  114. .refreshWord{
  115. width: 150upx;
  116. height: 26upx;
  117. font-size: 24upx;
  118. line-height: 26upx;
  119. text-align: center;
  120. border-radius: 26upx;
  121. }
  122. .refresh {
  123. min-width: 50upx;
  124. display: flex;
  125. align-items: center;
  126. justify-content: center;
  127. height: 50upx;
  128. background: #FFFFFF;
  129. box-shadow: 0 0 16upx 0 rgba(0, 0, 0, 0.10);
  130. border-radius: 50upx;
  131. }
  132. .refreshCirle {
  133. width: 26upx;
  134. height: 26upx;
  135. border-radius: 50%;
  136. display: inline-block;
  137. position: relative;
  138. border: 6upx solid black;
  139. border-bottom-color: transparent;
  140. border-top-color: transparent;
  141. }
  142. .animation {
  143. animation: rotate 1.1s infinite;
  144. animation-timing-function: cubic-bezier(0.3, 1.65, 0.7, -0.65);
  145. }
  146. @keyframes rotate {
  147. 0% {
  148. transform: rotate(0deg);
  149. }
  150. 100% {
  151. transform: rotate(360deg);
  152. }
  153. }
  154. .true {
  155. color: black;
  156. }
  157. .iconYes {
  158. width: 34upx;
  159. height: 34upx;
  160. }
  161. </style>