MovableView 可移动的视图容器

基础样式

MovableView 可移动的视图容器 - 图1

  1. <se-movable-area class="movable-area" width="300px" height="300px">
  2. <se-movable-view class="movable-view" direction="all"></se-movable-view>
  3. </se-movable-area>
  4. <style>
  5. .movable-area {
  6. background: #eee;
  7. }
  8. .movable-view {
  9. width: 80px;
  10. height: 80px;
  11. background: #01d567;
  12. }
  13. </style>

移动至指定位置

MovableView 可移动的视图容器 - 图2

  1. <se-button @click="move(30, 30)">移动到(30,30)</se-button>
  2. <se-movable-area class="movable-area" width="300px" height="300px">
  3. <se-movable-view class="movable-view" ref="movableView" :x="x" :y="y"></se-movable-view>
  4. </se-movable-area>
  5. <script>
  6. export default {
  7. data() {
  8. return {
  9. x: 0,
  10. y: 0
  11. }
  12. },
  13. methods: {
  14. move(x, y) {
  15. this.$refs.movableView.setPosition(x, y)
  16. }
  17. }
  18. }
  19. </script>
  20. <style>
  21. .movable-area {
  22. margin-bottom: 10px;
  23. background: #eee;
  24. }
  25. .movable-view {
  26. width: 80px;
  27. height: 80px;
  28. background: #01d567;
  29. }
  30. </style>

扩大效果

MovableView 可移动的视图容器 - 图3

<se-button @click="scale">扩大两倍</se-button>

<se-movable-area class="movable-area" width="300px" height="300px">
  <se-movable-view class="movable-view" ref="movableView" :x="x" :y="y"></se-movable-view>
</se-movable-area>

<script>
  export default {
    data() {
      return {
        x: 50,
        y: 50
      }
    },
    methods: {
      scale() {
        this.$refs.movableView.setScale(2)
      }
    }
  }
</script>

<style>
  .movable-area {
    margin-bottom: 10px;
    background: #eee;
  }
  .movable-view {
    width: 60px;
    height: 60px;
    background: #01d567;
  }
</style>

超过可移动区域后可移动

MovableView 可移动的视图容器 - 图4

<se-movable-area class="movable-area" width="300px" height="300px">
  <se-movable-view class="movable-view" :out-of-bounds="true"></se-movable-view>
</se-movable-area>

<style>
  .movable-area {
    background: #eee;
  }
  .movable-view {
    width: 80px;
    height: 80px;
    background: #01d567;
  }
</style>

movable-view 区域大于 movable-area

MovableView 可移动的视图容器 - 图5

<se-movable-area class="movable-area" width="200px" height="200px">
  <se-movable-view class="movable-view" :out-of-bounds="true">
    hello
  </se-movable-view>
</se-movable-area>

<style>
  .movable-area {
    background: #eee;
  }
  .movable-view {
    width: 300px;
    color: #fff;
    line-height: 300px;
    text-align: center;
    background: #01d567;
  }
</style>

禁止移动

MovableView 可移动的视图容器 - 图6

<se-movable-area class="movable-area" width="300px" height="300px">
  <se-movable-view class="movable-view" :disabled="true"></se-movable-view>
</se-movable-area>

<style>
  .movable-area {
    background: #eee;
  }
  .movable-view {
    width: 80px;
    height: 80px;
    background: #f43131;
  }
</style>

Props

属性类型默认值必填说明
directionstringall移动方向,属性值有 all、vertical、horizontal、none
inertiabooleanfalse是否带有惯性
out-of-boundsbooleanfalse是否可以超出边界
xnumber0x 轴方向的偏移
ynumber0y 轴方向的偏移
animationbooleanfalse是否使用动画
disabledbooleanfalse是否禁用
scale-valuenumber1缩放的倍数
scale-minnumber1缩放倍数最小值
scale-maxnumber1缩放倍数最大值

Events

名称类型说明
changeEventHandle改变时触发
scaleEventHandle缩放时触发