小程序在520節(jié)日前夜,讓程序員們又躁動了一把,更新了一些很誘人的功能,如內(nèi)容轉(zhuǎn)發(fā)API,iBeacon API,振動API,屏幕亮度調(diào)節(jié)API等,也增強了地圖組件的功能。 ... ...
此次的更新中,也新增了一個UI組件,它就是視圖組件movable-view,它需要配合movable-area來一起使用。簡單來說,它就是一個支持在指定區(qū)域內(nèi)可以拖動內(nèi)容的容器。我們來看一個簡單的示例:
<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大小的一個可拖動區(qū)域(紅色),然后在這個區(qū)域內(nèi)放置了一個大小為50x50的可以拖動內(nèi)容movable-view(藍色),這個可拖動內(nèi)容的direction設置為all,表示可以在任意方向上進行拖動。

在一個movable-area標簽中,其實不止可以放一個movable-view,它支持放置多個movable-view,看以下例子:
<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>


movable-view的direction屬性支持以下四個值:
前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)的位置上了:

好了,小程序的拖動組件的功能大致就這樣簡單的介紹一下,希望對你有所幫助。