Skip to content
# t-movable-view

MovableView 可移动视图

t-movable-view 组件介绍 ​

t-movable-view 是可移动的视图容器,必须在 t-movable-area 组件内使用。支持拖动、惯性、边界控制和缩放等功能,通过在视图层内部处理拖动,避免逻辑层和视图层之间的通信损耗。

t-movable-view 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-movable-view 基础用法 ​

基础用法参考 demo/movable/movable.uvue,在 t-movable-area 内使用。

vue
<template>
	<view class="p-15">
		<tui-theme-switch></tui-theme-switch>
		<t-card class="mb-15"
				title="MovableArea 拖动区域"
				sub-title="补充官方movable-area不支持APP,小程序开发的时候,避免过多的写条件编译"></t-card>
		<t-section title="拖动"
				   class="mb-15"></t-section>
		<t-movable-area :class="[`w-100% h-150 mb-15 tvg r-10`]">
			<t-movable-view :class="[`twh-60 r-10 fc tbg-pn`]"
							:x="x"
							:y="y"
							direction="all"
							:inertia="true"
							:out-of-bounds="true"
							@change="onChange">
				<t-text :fore="true"
						type="primary">Text</t-text>
			</t-movable-view>
		</t-movable-area>
		<t-section title="绽放"
				   class="mb-15"></t-section>
		<t-movable-area :class="[`w-100% h-200 mb-15 tvg r-10`]"
						:scale-area="true">
			<t-movable-view :class="[`twh-60 r-10 fc tbg-pn`]"
							:x="x"
							:y="y"
							:scale-value="scale"
							:scale="true"
							:inertia="true"
							:out-of-bounds="true"
							direction="all"
							@change="onChange">
				<t-text :fore="true"
						type="primary">Text</t-text>
			</t-movable-view>
		</t-movable-area>

		<t-button @click="scale+=0.2"
				  type="primary">缩放</t-button>
	</view>
</template>
<script setup>
	const x = ref(0)
	const y = ref(0)
	const scale = ref(1)

	function onChange(e : UTSJSONObject) {
		// console.log(e)
	}
</script>

t-movable-view Props ​

属性名说明类型默认值
direction移动方向,可选 all、vertical、horizontal、nonestring'all'
inertia是否带有惯性booleanfalse
outOfBounds是否可以超出边界booleanfalse
xX 坐标number0
yY 坐标number0
damping阻尼系数number20
friction摩擦系数number2
disabled是否禁用booleanfalse
scale是否支持缩放booleanfalse
scaleMin最小缩放比例number0.5
scaleMax最大缩放比例number10
scaleValue缩放比例number1
animation是否使用动画booleantrue
path点击组件后跳转的页面路径string''
hover是否启用点击效果booleanfalse
type组件主题类型string''
effect组件显示主题string''
size组件尺寸string''

direction 可选值 ​

值说明
all全方向移动
vertical仅垂直方向移动
horizontal仅水平方向移动
none不可移动

t-movable-view Events ​

事件名说明回调参数
change拖动过程中触发{ x, y, source }
scale缩放过程中触发{ x, y, scale }

change 事件 source 值 ​

值说明
touch拖动
touch-out-of-bounds超出移动范围
out-of-bounds超出移动范围后的回弹
friction惯性
''setData

t-movable-view Slots ​

插槽名说明
default默认插槽,放置可移动的内容