movable-view.uvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="page-body">
  3. <page-head title="movable-view,可拖动视图"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view class="uni-title uni-common-mt">
  6. 示例 1
  7. <text>\nmovable-view 区域小于 movable-area</text>
  8. </view>
  9. <movable-area>
  10. <movable-view :x="x" :y="y" direction="all" @change="onChange">text</movable-view>
  11. </movable-area>
  12. <view @tap="tap" class="uni-link uni-center uni-common-mt">
  13. 点击这里移动至 (30px, 30px)
  14. </view>
  15. <view class="uni-title uni-common-mt">
  16. 示例 2
  17. <text>\nmovable-view区域大于movable-area</text>
  18. </view>
  19. <movable-area>
  20. <movable-view class="max" direction="all">text</movable-view>
  21. </movable-area>
  22. <view class="uni-title uni-common-mt">
  23. 示例 3
  24. <text>\n只可以横向移动</text>
  25. </view>
  26. <movable-area>
  27. <movable-view direction="horizontal">text</movable-view>
  28. </movable-area>
  29. <view class="uni-title uni-common-mt">
  30. 示例 4
  31. <text>\n只可以纵向移动</text>
  32. </view>
  33. <movable-area>
  34. <movable-view direction="vertical">text</movable-view>
  35. </movable-area>
  36. <view class="uni-title uni-common-mt">
  37. 示例 5
  38. <text>\n可超出边界</text>
  39. </view>
  40. <movable-area>
  41. <movable-view direction="all" out-of-bounds>text</movable-view>
  42. </movable-area>
  43. <view class="uni-title uni-common-mt">
  44. 示例 6
  45. <text>\n带有惯性</text>
  46. </view>
  47. <movable-area>
  48. <movable-view direction="all" inertia>text</movable-view>
  49. </movable-area>
  50. <view class="uni-title uni-common-mt">
  51. 示例 7
  52. <text>\n可放缩</text>
  53. </view>
  54. <movable-area scale-area>
  55. <movable-view direction="all" @scale="onScale" scale scale-min="0.5" scale-max="4"
  56. :scale-value="scale">text</movable-view>
  57. </movable-area>
  58. <view @tap="tap2" class="uni-link uni-center uni-common-mt" style="padding-bottom:40px;">
  59. 点击这里放大3倍
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script lang="uts">
  65. export default {
  66. data() {
  67. return {
  68. x: 0,
  69. y: 0,
  70. scale: 2,
  71. old: {
  72. x: 0,
  73. y: 0,
  74. scale: 2
  75. }
  76. }
  77. },
  78. methods: {
  79. tap: function (e) {
  80. // 解决view层不同步的问题
  81. this.x = this.old.x
  82. this.y = this.old.y
  83. this.$nextTick(function () {
  84. this.x = 30
  85. this.y = 30
  86. })
  87. },
  88. tap2() {
  89. // 解决view层不同步的问题
  90. this.scale = this.old.scale
  91. this.scale = this.old.scale
  92. this.$nextTick(function () {
  93. this.scale = 3
  94. })
  95. },
  96. onChange: function (e) {
  97. this.old.x = e.detail.x
  98. this.old.y = e.detail.y
  99. },
  100. onScale: function (e) {
  101. this.old.scale = e.detail.scale
  102. }
  103. }
  104. }
  105. </script>
  106. <style>
  107. movable-view {
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. height: 75px;
  112. width: 75px;
  113. background-color: #007AFF;
  114. color: #fff;
  115. }
  116. movable-area {
  117. height: 150px;
  118. width: 100%;
  119. background-color: #D8D8D8;
  120. overflow: hidden;
  121. }
  122. .max {
  123. width: 250px;
  124. height: 250px;
  125. }
  126. </style>