小程序的更新中,也新增了一个UI组件,它就是视图组件movable-view,它须要配合movable-area来一块儿使用。简单来讲,它就是一个支持在指定区域内能够拖动内容的容器。咱们来看一个简单的示例:小程序
<movable-area style="height: 200px;width: 200px;background: red;"> <movable-view direction="all" style="height: 50px; width: 50px; background: blue;"> </movable-view> </movable-area>
咱们用movable-area设定了一个200x200大小的一个可拖动区域(红色),而后在这个区域内放置了一个大小为50x50的能够拖动内容movable-view(蓝色),这个可拖动内容的direction设置为all,表示能够在任意方向上进行拖动。spa
拖动演示3d
在一个movable-area标签中,其实不止能够放一个movable-view,它支持放置多个movable-view,看如下例子:code
<movable-area style="height: 200px;width: 200px;background: red;"> <!--蓝色任意方向拖动的内容--> <movable-view direction="all" style="height: 50px; width: 50px; background: blue;"> </movable-view> <!--黄色只能横向拖动的内容--> <movable-view direction="horizontal" style="height: 20px; width: 50px; background: yellow;"> </movable-view> </movable-area>
拖动演示2blog
movable-view的direction属性支持如下四个值:io
all - 任意方向拖动class
vertical - 纵向拖动容器
horizontal - 横向拖动程序
none - 不能拖动im
前3个值好理解。若是direction设置为最后这个none,则只能依靠设置x,y属性值来为它进行在movable-area中的定位:
<movable-area style="height: 200px;width: 200px;background: red;"> <movable-view direction="none" x="50" y="50" style="height: 50px; width: 50px; background: blue;"> </movable-view> </movable-area>
这段代码一运行,蓝色的movable-view就显示在了(50,50)的位置上了:
好了,小程序的拖动组件的功能大体就这样简单的介绍一下,但愿对你有所帮助。