index.js 1.2 KB

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