movable-view.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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" :scale-value="scale">text</movable-view>
  56. </movable-area>
  57. <view @tap="tap2" class="uni-link uni-center uni-common-mt" style="padding-bottom:80rpx;">
  58. 点击这里放大3倍
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. x: 0,
  68. y: 0,
  69. scale: 2,
  70. old: {
  71. x: 0,
  72. y: 0,
  73. scale: 2
  74. }
  75. }
  76. },
  77. methods: {
  78. tap: function(e) {
  79. // 解决view层不同步的问题
  80. this.x = this.old.x
  81. this.y = this.old.y
  82. this.$nextTick(function() {
  83. this.x = 30
  84. this.y = 30
  85. })
  86. },
  87. tap2() {
  88. // 解决view层不同步的问题
  89. this.scale = this.old.scale
  90. this.scale = this.old.scale
  91. this.$nextTick(function() {
  92. this.scale = 3
  93. })
  94. },
  95. onChange: function(e) {
  96. this.old.x = e.detail.x
  97. this.old.y = e.detail.y
  98. },
  99. onScale: function(e) {
  100. this.old.scale = e.detail.scale
  101. }
  102. }
  103. }
  104. </script>
  105. <style>
  106. movable-view {
  107. display: flex;
  108. align-items: center;
  109. justify-content: center;
  110. height: 150rpx;
  111. width: 150rpx;
  112. background-color: #007AFF;
  113. color: #fff;
  114. }
  115. movable-area {
  116. height: 300rpx;
  117. width: 100%;
  118. background-color: #D8D8D8;
  119. overflow: hidden;
  120. }
  121. .max {
  122. width:500rpx;
  123. height: 500rpx;
  124. }
  125. </style>