fly-to-cart.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="fly-to-cart"
  3. v-if="!hide"
  4. :style="{ width: self.width + 'px', height: self.height + 'px', top: top + 'px', left: left + 'px' }">
  5. <slot></slot>
  6. </view>
  7. </template>
  8. <script>
  9. import $flyInData from './fly-to-cart.js'
  10. export default {
  11. props: {
  12. self: Object,
  13. cart: Object
  14. },
  15. data() {
  16. return {
  17. count: 0,
  18. hide: true,
  19. finger: {},
  20. busPos: {},
  21. top: this.self.y - this.self.height / 2,
  22. left: this.self.x - this.self.width / 2
  23. }
  24. },
  25. methods: {
  26. fly() {
  27. const startPos = {
  28. x: this.self.x,
  29. y: this.self.y
  30. }
  31. const topPoint = { // 抛物线顶点位置
  32. x: Math.abs(this.self.x - this.cart.x) / 2,
  33. y: this.self.y - 175
  34. }
  35. const cartPos = {
  36. x: this.cart.x,
  37. y: this.cart.y
  38. }
  39. this.linePos = $flyInData([cartPos, topPoint, startPos], 30)
  40. this.hide = false
  41. this.startAnimation()
  42. },
  43. startAnimation() {
  44. let index = this.linePos.length
  45. this.timer = setInterval(() => {
  46. index --
  47. this.linePos[index] ? this.top = this.linePos[index].y : ''
  48. this.linePos[index] ? this.left = this.linePos[index].x : ''
  49. if (index < 1) {
  50. clearInterval(this.timer)
  51. this.hide = true
  52. }
  53. }, 20)
  54. }
  55. }
  56. }
  57. </script>
  58. <style lang="scss">
  59. .fly-to-cart {
  60. @include flex();
  61. z-index: 150;
  62. color: #FFFFFF;
  63. position: fixed;
  64. overflow: hidden;
  65. border-radius: 50%;
  66. background: $app-base-color;
  67. }
  68. </style>