Movable-area
组件类型:UxMovableAreaComponentPublicInstance
拖动或双指缩放区域
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
scaleArea | Boolean | false | 当里面的movable-view设置为支持双指缩放时,设置此值可将缩放手势生效区域修改为整个movable-area |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll :disabled="true">
<ux-card direction="column" icon="flag-filled" title="拖动区域" :bold="true">
<ux-text text="支持区域拖动, 作为官方还未支持APP端movable-area组件的补充, 功能与官方组件对齐"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="拖动" :bold="true">
<!-- 注意小程序端自定义组件不支持class绑定,支持style绑定样式 -->
<!-- #ifdef MP -->
<movable-area :style="areaStyle">
<movable-view :style="viewStyle" :x="x" :y="y" direction="all" :inertia="true" :out-of-bounds="true" @change="onChange">
<text class="text">Text</text>
</movable-view>
</movable-area>
<!-- #endif -->
<!-- #ifndef MP -->
<ux-movable-area :style="areaStyle">
<ux-movable-view :style="viewStyle" :x="x" :y="y" direction="all" :inertia="true" :out-of-bounds="true" @change="onChange">
<text class="text">Text</text>
</ux-movable-view>
</ux-movable-area>
<!-- #endif -->
</ux-card>
<ux-card direction="column" icon="arrowright" title="缩放" :bold="true">
<!-- #ifdef MP -->
<movable-area :style="areaStyle" :scale-area="true">
<movable-view :style="viewStyle" :x="x" :y="y" :scale-value="scale" :scale="true" :inertia="true" :out-of-bounds="true" direction="all" @change="onChange">
<text class="text" @click="scale+=0.2">Text</text>
</movable-view>
</movable-area>
<!-- #endif -->
<!-- #ifndef MP -->
<ux-movable-area :style="areaStyle" :scale-area="true">
<ux-movable-view :style="viewStyle" :x="x" :y="y" :scale-value="scale" :scale="true" :inertia="true" :out-of-bounds="true" direction="all" @change="onChange">
<text class="text" @click="scale+=0.2">Text</text>
</ux-movable-view>
</ux-movable-area>
<!-- #endif -->
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll :disabled="true">
<ux-card direction="column" icon="flag-filled" title="拖动区域" :bold="true">
<ux-text text="支持区域拖动, 作为官方还未支持APP端movable-area组件的补充, 功能与官方组件对齐"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="拖动" :bold="true">
<!-- 注意小程序端自定义组件不支持class绑定,支持style绑定样式 -->
<!-- #ifdef MP -->
<movable-area :style="areaStyle">
<movable-view :style="viewStyle" :x="x" :y="y" direction="all" :inertia="true" :out-of-bounds="true" @change="onChange">
<text class="text">Text</text>
</movable-view>
</movable-area>
<!-- #endif -->
<!-- #ifndef MP -->
<ux-movable-area :style="areaStyle">
<ux-movable-view :style="viewStyle" :x="x" :y="y" direction="all" :inertia="true" :out-of-bounds="true" @change="onChange">
<text class="text">Text</text>
</ux-movable-view>
</ux-movable-area>
<!-- #endif -->
</ux-card>
<ux-card direction="column" icon="arrowright" title="缩放" :bold="true">
<!-- #ifdef MP -->
<movable-area :style="areaStyle" :scale-area="true">
<movable-view :style="viewStyle" :x="x" :y="y" :scale-value="scale" :scale="true" :inertia="true" :out-of-bounds="true" direction="all" @change="onChange">
<text class="text" @click="scale+=0.2">Text</text>
</movable-view>
</movable-area>
<!-- #endif -->
<!-- #ifndef MP -->
<ux-movable-area :style="areaStyle" :scale-area="true">
<ux-movable-view :style="viewStyle" :x="x" :y="y" :scale-value="scale" :scale="true" :inertia="true" :out-of-bounds="true" direction="all" @change="onChange">
<text class="text" @click="scale+=0.2">Text</text>
</ux-movable-view>
</ux-movable-area>
<!-- #endif -->
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>
ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const x = ref(0)
const y = ref(0)
const scale = ref(1)
const areaStyle = computed(() => {
let css = new Map<string, any>()
css.set('width', '100%')
css.set('height', '150px')
css.set('background-color', '#f0f0f0')
return css
})
const viewStyle = computed(() => {
let css = new Map<string, any>()
css.set('width', '65px')
css.set('height', '65px')
css.set('border-radius', '5px')
css.set('display', 'flex')
css.set('flex-direction', 'column')
css.set('align-items', 'center')
css.set('justify-content', 'center')
css.set('background-color', 'royalblue')
return css
})
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/movable-area.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
function onChange(e: UTSJSONObject) {
console.log(e)
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
</script>
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const x = ref(0)
const y = ref(0)
const scale = ref(1)
const areaStyle = computed(() => {
let css = new Map<string, any>()
css.set('width', '100%')
css.set('height', '150px')
css.set('background-color', '#f0f0f0')
return css
})
const viewStyle = computed(() => {
let css = new Map<string, any>()
css.set('width', '65px')
css.set('height', '65px')
css.set('border-radius', '5px')
css.set('display', 'flex')
css.set('flex-direction', 'column')
css.set('align-items', 'center')
css.set('justify-content', 'center')
css.set('background-color', 'royalblue')
return css
})
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/movable-area.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
function onChange(e: UTSJSONObject) {
console.log(e)
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
</script>
css
<style lang="scss">
.area {
width: 100%;
height: 150px;
background-color: #f0f0f0;
}
.view {
width: 65px;
height: 65px;
border-radius: 5px;
background-color: royalblue;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.text {
color: white;
font-weight: bold;
font-size: 15px;
}
</style>
<style lang="scss">
.area {
width: 100%;
height: 150px;
background-color: #f0f0f0;
}
.view {
width: 65px;
height: 65px;
border-radius: 5px;
background-color: royalblue;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.text {
color: white;
font-weight: bold;
font-size: 15px;
}
</style>