index.js 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. Component({
  2. properties: {
  3. radius: {
  4. type: Number
  5. }, //半径 单位px
  6. useSlot: {
  7. type: Boolean
  8. }
  9. },
  10. data: {
  11. top: "550px",
  12. left: "345px",
  13. viewHeight: null
  14. },
  15. lifetimes: {
  16. attached: function () {
  17. let that = this;
  18. wx.getSystemInfo({
  19. success: (res => that.setData({
  20. viewHeight: res.windowHeight
  21. }))
  22. });
  23. },
  24. },
  25. methods: {
  26. viewTouchMove(e) {
  27. let left = e.touches[0].pageX;
  28. if (left > (375 - this.data.radius)) left = 375 - (this.data.radius / 2);
  29. if (left < 0 + this.data.radius) left = 0 + this.data.radius;
  30. let top = e.touches[0].pageY;
  31. if (top < 0 + this.data.radius) top = 0 + this.data.radius;
  32. if (top > this.data.viewHeight - this.data.radius) top = this.data.viewHeight - this.data.radius;
  33. this.setData({
  34. left: left + 'px',
  35. top: top + 'px'
  36. })
  37. }
  38. }
  39. })