uniapp的movable-view、movable-area

本文涉及的产品
文本翻译,文本翻译 100万字符
文档翻译,文档翻译 1千页
语种识别,语种识别 100万字符
简介: uniapp的movable-view、movable-area

uniapp的movable-view、movable-area

movable-view:

  • 可以在页面中拖拽滑动
  • 必须在movable-area组件中,并且必须是直接子节点
  • 必须设置width和height属性,不设置默认为10px
  • 提供特殊事件:htouchmove和vtouchmove

movable-area:

  • 表示可拖动的范围
  • 可包含多个movable-view组件
  • 必须设置width和height属性,不设置默认为10px

以下是完整示例代码

movable-view 区域小于 movable-area
<view class="uni-title uni-common-mt">
  示例 1
  <text>\nmovable-view 区域小于 movable-area</text>
</view>
<movable-area>
  <movable-view :x="x" :y="y" direction="all" @change="onChange">text</movable-view>
</movable-area>
<view @tap="tap" class="uni-link uni-center uni-common-mt">
  点击这里移动至 (30px, 30px)
</view>
<script>
  export default {
    data() {
      return {
        x: 0,
        y: 0,
        scale: 2,
        old: {
          x: 0,
          y: 0,
          scale: 2
        }
      }
    },
    methods: {
      tap: function(e) {
        // 解决view层不同步的问题
        this.x = this.old.x
        this.y = this.old.y
        this.$nextTick(function() {
          this.x = 30
          this.y = 30
        })
      },
      onChange: function(e) {
        this.old.x = e.detail.x
        this.old.y = e.detail.y
      }
    }
  }
</script>

nmovable-view区域大于movable-area
<view class="uni-title uni-common-mt">
示例 2
  <text>\nmovable-view区域大于movable-area</text>
</view>
<movable-area>
  <movable-view class="max" direction="all">text</movable-view>
</movable-area>

只可以横向移动
<view class="uni-title uni-common-mt">
  示例 3
  <text>\n只可以横向移动</text>
</view>
<movable-area>
  <movable-view direction="horizontal">text</movable-view>
</movable-area>

只可以纵向移动
<view class="uni-title uni-common-mt">
  示例 4
  <text>\n只可以纵向移动</text>
</view>
<movable-area>
  <movable-view direction="vertical">text</movable-view>
</movable-area>

可超出边界
<view class="uni-title uni-common-mt">
  示例 5
  <text>\n可超出边界</text>
</view>
<movable-area>
  <movable-view direction="all" out-of-bounds>text</movable-view>
</movable-area>

带有惯性
<view class="uni-title uni-common-mt">
  示例 6
  <text>\n带有惯性</text>
</view>
<movable-area>
  <movable-view direction="all" inertia>text</movable-view>
</movable-area>

可缩放
<view class="uni-title uni-common-mt">
  示例 7
  <text>\n可放缩</text>
</view>
<movable-area scale-area>
  <movable-view direction="all" @scale="onScale" scale scale-min="0.5" scale-max="4" :scale-value="scale">text</movable-view>
</movable-area>
<view @tap="tap2" class="uni-link uni-center uni-common-mt" style="padding-bottom:80rpx;">
  点击这里放大3倍
</view>


相关文章
|
6月前
|
Web App开发 小程序 Android开发
Uniapp 视图容器 随机拖拽滑动 放大缩小 movable-view movable-area
Uniapp 视图容器 随机拖拽滑动 放大缩小 movable-view movable-area
192 0
|
Java
viewpage 添加fragment 报错 viewpage demo LayoutInflater 自定义控件轮播图demo
viewpage 添加fragment 报错 viewpage demo LayoutInflater 自定义控件轮播图demo
110 0
viewpage 添加fragment 报错 viewpage demo LayoutInflater 自定义控件轮播图demo
|
小程序 容器
讲述小程序之组件视图容器之movable-area与movable-view
讲述小程序之组件视图容器之movable-area与movable-view
391 0
讲述小程序之组件视图容器之movable-area与movable-view
|
缓存 Android开发 容器
ViewPager刷新问题原理分析及解决方案(FragmentPagerAdapter+FragementStatePagerAdapter)
ViewPager刷新问题原理分析及解决方案(FragmentPagerAdapter+FragementStatePagerAdapter)
575 0
ViewPager刷新问题原理分析及解决方案(FragmentPagerAdapter+FragementStatePagerAdapter)
Dialog显示引起的问题 Activity has leaked window DecorView@5704632[] that was originally added here
Dialog显示引起的问题 Activity has leaked window DecorView@5704632[] that was originally added here
1099 0
|
Java Android开发 Python
RecyclerView实现多type页面
目录介绍 01.先看看实际需求 02.adapter实现多个type 03.这样写的弊端 04.如何优雅实现adapter封装 好消息 博客笔记大汇总【16年3月到至今】,包括Java基础及深入知识点,Android技术博客,Python学习笔记等等,还包括平时开发中遇到的bug汇总,当然也...
978 0
|
.NET 开发框架 存储