Supported from basic library 1.11.0. Earlier versions require compatibility handling (About the Mini-program Basic Library).
movable-area
Movable area of movable-view.
The width and height attributes of movable-area are required. Default: 10px.
movable-view
Draggable view container that slides within the page.
|
Attribute |
Type |
Default value |
Description |
Minimum version |
|
direction |
String |
none |
Movement direction of movable-view. Valid values: |
- |
|
x |
Number |
0 |
X-axis offset, mapped to the |
- |
|
y |
Number |
0 |
Y-axis offset, mapped to the |
- |
|
disabled |
Boolean |
false |
Disables the button. |
- |
|
onTouchStart |
EventHandle |
- |
Triggered when a touch starts. |
|
|
onTouchMove |
EventHandle |
- |
Triggered when a touch moves. |
|
|
onTouchEnd |
EventHandle |
- |
Triggered when a touch ends. |
|
|
onTouchCancel |
EventHandle |
- |
Triggered when a touch is canceled, for example, by an incoming call or pop-up. |
|
|
onChange |
- |
Triggered during dragging. |
- |
|
|
onChangeEnd |
EventHandle |
- |
Triggered after dragging ends. |
- |
Code sample
<movable-area style="width: 100px;height: 100px;background-color: red;margin-left: 100px;">
<movable-view
onChange="onMovableViewChange"
onChangeEnd="onMovableViewChangeEnd"
direction="vertical"
x="{{10}}"
y="{{10}}"
style="width: 40px;height: 40px;background-color: rgba(0, 0, 0, 0.5);"
>
<view onTap="onTapMovableView">movable-view</view>
</movable-view>
</movable-area>
Cautions
-
The width and height attributes of
movable-vieware required. Default: 10 px. -
movable-viewuses absolute positioning by default (do not modify). top and left default to 0 px. -
When
movable-viewis smaller thanmovable-area, it moves withinmovable-area. When larger,movable-viewmust fully covermovable-area. Each axis is evaluated independently. -
movable-viewmust be a direct child of<movable-area/>. Otherwise, it cannot move.