index.js 889 B

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