flyInCart.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!-- uni兼职开发加qq1844014810 -->
  2. <template>
  3. <view class="relative">
  4. <view class="ball" v-for="(d,i) in balls" :key="i" :style=" d.inited ? 'transition: transform .4s cubic-bezier(.6,-0.63,.94,.71); transform: translate3d(0, ' + offsetY + 'px,0); top: ' + ballY + 'px;' : '' ">
  5. <view class="inner arbg" :style="d.inited ? 'transition: transform .4s linear; transform: translate3d( ' + offsetX + 'px,0,0); left: ' + ballX + 'px; opacity: 1;' : '' "></view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. props:{
  12. cartBasketRect:Object,// 购物车篮的rect信息
  13. },
  14. data() {
  15. return {
  16. offsetX: 0,
  17. offsetY: 0,
  18. ballX: 0,
  19. ballY: 0,
  20. balls: {},
  21. //避免抖动
  22. lastEvent:'',
  23. lastId:''
  24. }
  25. },
  26. created() {
  27. let balls = [];
  28. for (let i = 0; i < 5; i++) {
  29. balls.push({ inited: false });
  30. }
  31. this.balls = balls
  32. },
  33. methods:{
  34. getBalls() {
  35. return balls;
  36. },
  37. addToCart (e,id) {
  38. if(!id){
  39. this.lastId = ''
  40. return
  41. }
  42. const self = this
  43. if(this.lastId == id){
  44. e = this.lastEvent
  45. }else{
  46. this.lastId = id
  47. this.lastEvent = e
  48. }
  49. //((res.width + that.ballWidth ) / 2 - that.ballWidth);
  50. let ballX = e.left
  51. let ballY = e.top
  52. this.offsetX = -Math.abs(this.cartBasketRect.left - ballX + 10)
  53. this.offsetY = Math.abs(this.cartBasketRect.top - ballY +(this.cartBasketRect.height/1.5))
  54. this.ballX = ballX
  55. this.ballY = ballY
  56. for (let i = 0; i < 5; i++) {
  57. if (!this.balls[i].inited) {
  58. this.balls[i].inited = true
  59. setTimeout(() => {
  60. self.balls[i].inited= false
  61. }, 500);
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. </script>
  69. <style scoped>
  70. .ball {
  71. position: fixed;
  72. z-index:99999;
  73. }
  74. .ball .inner {
  75. background: #ff5722;
  76. width: 15px;
  77. height: 15px;
  78. position: fixed;
  79. border-radius: 50%;
  80. opacity: 0;
  81. }
  82. </style>