index.js 1023 B

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