index.js 797 B

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