drop-card@old.uvue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="root">
  3. <view class="card"
  4. :style="{'top':Math.abs(x)/-60 + 90 +'px',transform:'scale('+(movePercent/10+0.80)+')','height':cardHeight+'px'}">
  5. <image class="user-img" :src="userList[0]" :style="{'height':cardHeight+'px'}"></image>
  6. </view>
  7. <view class="card"
  8. :style="{'top':Math.abs(x)/-30 + 45 +'px',transform:'scale('+(movePercent/10+0.90)+')','height':cardHeight+'px'}">
  9. <image class="user-img" :src="userList[1]" :style="{'height':cardHeight+'px'}"></image>
  10. </view>
  11. <view @touchmove="touchmove" @touchstart="touchstart" @touchend="touchend"
  12. :style="{'transform':'translate('+x+'px,'+y+'px) rotate('+x/-30+'deg)','height':cardHeight+'px'}" class="card">
  13. <image class="user-img" :src="userList[2]" :style="{'height':cardHeight+'px'}"></image>
  14. <view class="state">
  15. <image class="state-icon like" :style="{'opacity':x < 0 ? 0 : movePercent * 10}" src="/static/template/drop-card/like.png" mode="widthFix"></image>
  16. <image class="state-icon dislike" :style="{'opacity':x > 0 ? 0 : movePercent * 10}" src="/static/template/drop-card/dislike.png" mode="widthFix"></image>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script lang="uts">
  22. let sX : number = 0,
  23. sY : number = 0,
  24. screenWidth : number = 1;
  25. export default {
  26. data() {
  27. return {
  28. x: 0,
  29. y: 0,
  30. cardHeight:1,
  31. userList: [
  32. 'https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/drop-card-1.jpg',
  33. 'https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/drop-card-2.jpg',
  34. 'https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/drop-card-3.jpg'
  35. ] as string.ImageURIString[]
  36. }
  37. },
  38. computed: {
  39. movePercent() : number {
  40. return Math.abs(this.x) / screenWidth
  41. },
  42. likeOpacity() : number{
  43. return this.x < 0 ? 0 : this.movePercent * 100
  44. },
  45. dislikeOpacity() : number{
  46. return this.x > 0 ? 0 : this.movePercent * 100
  47. }
  48. },
  49. onLoad() {
  50. uni.getSystemInfo({
  51. success: (e) => {
  52. console.log('e',e);
  53. screenWidth = e.screenWidth
  54. this.cardHeight = e.screenHeight - 200
  55. }
  56. })
  57. },
  58. methods: {
  59. changeUserList() {
  60. let user:string = this.userList[this.userList.length - 1]
  61. this.userList.unshift(user)
  62. this.userList.pop()
  63. this.x = 0;
  64. this.y = 0;
  65. },
  66. touchstart(e : TouchEvent) {
  67. sX = e.touches[0].screenX;
  68. sY = e.touches[0].screenY;
  69. },
  70. touchmove(e : TouchEvent) {
  71. this.x += e.touches[0].screenX - sX;
  72. this.y += e.touches[0].screenY - sY;
  73. sX = e.touches[0].screenX;
  74. sY = e.touches[0].screenY;
  75. },
  76. touchend() {
  77. if (this.x > screenWidth / 6) {
  78. let interval : number = 0;
  79. interval = setInterval(() => {
  80. this.x += 10
  81. this.y += 3
  82. if (this.x > screenWidth) {
  83. clearInterval(interval)
  84. this.changeUserList()
  85. }
  86. }, 6)
  87. } else if (this.x < screenWidth * -1 / 6) {
  88. let interval : number = 0;
  89. interval = setInterval(() => {
  90. this.x -= 10
  91. this.y += 3
  92. if (this.x < -screenWidth) {
  93. clearInterval(interval)
  94. this.changeUserList()
  95. }
  96. }, 6)
  97. } else {
  98. this.x = 0
  99. this.y = 0
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style>
  106. .root {
  107. flex: 1;
  108. position: relative;
  109. }
  110. .card {
  111. width: 350px;
  112. height: 375px;
  113. position: absolute;
  114. margin: 0 12px;
  115. margin-top: 30px;
  116. border-radius: 10px;
  117. color: #FFF;
  118. box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  119. }
  120. .user-img{
  121. border-radius: 10px;
  122. }
  123. .state {
  124. top: 10px;
  125. left: 10px;
  126. width: 325px;
  127. padding: 4px;
  128. position: absolute;
  129. flex-direction: row;
  130. justify-content: space-between;
  131. }
  132. .state-icon {
  133. width: 30px;
  134. height: 30px;
  135. border: 1px solid #FFF;
  136. background-color: #FFF;
  137. padding: 3px;
  138. border-radius: 100px;
  139. box-shadow: 0 0 1px #EBEBEB;
  140. }
  141. </style>