movable-view 可移动视图容器
值 | 说明 |
---|
all | 水平方向和垂直方向 |
vertical | 垂直方向 |
horizontal | 水平方向 |
none | 不可移动 |
扫码体验
代码示例 1: movable-view区域小于movable-area
data: {
x1: 30,
y1: 30,
},
move() {
this.setData({
x1: 50,
y1: 50
})
}
});
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
movable-view区域大于movable-area
</view>
<movable-area>
<!-- 添加大于movable-area的class -->
<movable-view x="{=x=}" y="{=y=}" class="bigger-area" direction="all">text</movable-view>
</movable-area>
</view>
</view>
Page({
data: {
x: 30,
y: 30
},
});
代码示例 3:只可以横向移动
<view class="card-area">
<view class="top-description border-bottom">
</view>
<movable-area htouchmove>
<movable-view x="{=x=}" y="{=y=}" direction="horizontal">text</movable-view>
</movable-area>
</view>
代码示例 4:只可以纵向移动
<view class="card-area">
只可以纵向移动
</view>
<movable-area vtouchmove>
<movable-view x="{=x=}" y="{=y=}" direction="vertical">text</movable-view>
</movable-area>
</view>
Page({
data: {
x: 30,
y: 30
},
});
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
可超出边界
</view>
<movable-area>
<movable-view x="{=x=}" y="{=y=}" direction="all" out-of-bounds>text</movable-view>
</movable-area>
</view>
</view>
Page({
data: {
x: 30,
y: 30
},
});
代码示例 6: 带有惯性
Page({
data: {
x: 30,
y: 30
},
});
代码示例 7: 可放缩
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
</view>
<movable-area>
<movable-view x="{=x=}" y="{=y=}" direction="all" animation="false" bindchange="onChange" bindscale="onScale" scale scale-min="0.5" scale-max="4" scale-value="{{scale}}">
text
</movable-view>
</movable-area>
<button bind:tap="scale" class="scale-button" type="primary">点击放大3倍</button>
</view>
</view>
Page({
data: {
x: 30,
y: 30,
scale: 1
},
move() {
this.setData({
x1: 50,
y1: 50
})
},
scale() {
this.setData({
scale: 3
})
},
onChange(e) {
console.log(e.detail)
},
onScale(e) {
console.log(e.detail)
}
});
<view class="wrap">
<movable-area style="height: {{height}}px; width: {{width}}px; background-color: #f5f5f5">
<movable-view x="{=x=}" y="{=y=}" direction="all" animation="false" bindchange="onChange" bindscale="onScale" scale scale-min="0.5" scale-max="4">
菜单
</movable-view>
</view>
- Tip:movable-view 必须设置 width 和 height 属性,不设置默认为 10px。
- Tip:movable-view 默认为绝对定位,top 和 left 属性为 0px。
- Tip:当 movable-view 小于 movable-area 时,movable-view 的移动范围是在 movable-area 内。
- Tip:当 movable-view 大于 movable-area 时,movable-view 的移动范围必须包含 movable-area(x 轴方向和 y 轴方向分开考虑)。
- Tip:movable-view 必须在组件中,并且必须是直接子节点,否则不能移动。