百度智能小程序組件 視圖容器

2020-08-12 09:51 更新

view


解釋:視圖容器。

屬性說明:

屬性名 類型 默認(rèn)值 說明
hover-class String none 指定按下去的樣式類。當(dāng) hover-class=”none” 時,沒有點(diǎn)擊態(tài)效果
hover-stop-propagation Boolean false 指定是否阻止本節(jié)點(diǎn)的祖先節(jié)點(diǎn)出現(xiàn)點(diǎn)擊態(tài)
hover-start-time Number 50 按住后多久出現(xiàn)點(diǎn)擊態(tài),單位毫秒
hover-stay-time Number 400 手指松開后點(diǎn)擊態(tài)保留時間,單位毫秒

示例:

<view class="single-text-area">
<view class="view-more">
<text>點(diǎn)擊加載更多</text>
</view>
</view>

Bug & Tip:

1、tip: 如果需要使用滾動視圖,請使用 scroll-view;

scroll-view


解釋:可滾動視圖區(qū)域。

屬性說明:

屬性名 類型 默認(rèn)值 說明
scroll-x Boolean false 允許橫向滾動
scroll-y Boolean false 允許縱向滾動
upper-threshold Number 50 距頂部/左邊多遠(yuǎn)時(單位 px),觸發(fā) scrolltoupper 事件
lower-threshold Number 50 距底部/右邊多遠(yuǎn)時(單位 px),觸發(fā) scrolltolower 事件
scroll-top Number 設(shè)置豎向滾動條位置。要動態(tài)設(shè)置滾動條位置,用法scroll-top=”{= scrollTop =}”
scroll-left Number 設(shè)置橫向滾動條位置。要動態(tài)設(shè)置滾動條位置,用法scroll-left=”{= scrollLeft =}”
scroll-into-view String 值應(yīng)為某子元素 id(id 不能以數(shù)字開頭)。設(shè)置哪個方向可滾動,則在哪個方向滾動到該元素
scroll-with-animation Boolean false 在設(shè)置滾動條位置時使用動畫過渡
bindscrolltoupper EventHandle 滾動到頂部/左邊,會觸發(fā) scrolltoupper 事件
bindscrolltolower EventHandle 滾動到底部/右邊,會觸發(fā) scrolltolower 事件
bindscroll EventHandle 滾動時觸發(fā), event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}

注意:使用豎向滾動時,需要給 <scroll-view/> 一個固定高度,通過 CSS 設(shè)置 height。

示例:

<scroll-view scroll-y style="height: 300px;"
    bind:scrolltoupper="upper" bind:scrolltolower="lower" scroll-into-view="four"
    upper-threshold="10"  lower-threshold="10" scroll-top="150" bind:scroll="myscroll">
    <view id="one" class="bg-red">view1</view>
    <view id="two" class="bg-green">view2</view>
    <view id="three" class="bg-yellow">view3</view>
    <view id="four" class="bg-blue">view4</view>
</scroll-view>
.bg-red, .bg-yellow, .bg-blue, .bg-green {
    height: 150px;
    text-align: center;
}
.bg-red {
    background: #FFB6C1;
}
.bg-yellow {
    background: #FFD700;
}
.bg-blue {
    background: #87CEFA;
}
.bg-green {
    background: #98FB98;
}
Page({
    upper: e => {
        console.log('upper', e);
    },
    lower: e => {
        console.log('lower', e);
    },
    myscroll: e => {
        console.log('scroll', e);
    }
});
Bug & Tip: 1、tip: 請勿在 scroll-view 中使用 textarea、map、canvas、video 組件; 2、tip: scroll-into-view 的優(yōu)先級高于 scroll-top、scroll-left; 3、tip: 在滾動 scroll-view 時會阻止頁面回彈,所以在 scroll-view 中滾動,是無法觸發(fā) onPullDownRefresh; 4、tip: 若要使用下拉刷新,請使用頁面的滾動,而不是 scroll-view;

swiper


解釋:滑塊視圖容器。

屬性說明:

屬性名 類型 默認(rèn)值 說明
indicator-dots Boolean false 是否顯示面板指示點(diǎn)
indicator-color Color rgba(0, 0, 0, .3) 指示點(diǎn)顏色
indicator-active-color Color #333 當(dāng)前選中的指示點(diǎn)顏色件
autoplay Boolean false 是否自動切換
current Number 0 當(dāng)前所在頁面的 index
interval Number 5000 自動切換時間間隔
duration Number 500 滑動動畫時長
circular Boolean false 是否采用銜接滑動
vertical Boolean false 滑動方向是否為縱向
bindchange EventHandle current 改變時會觸發(fā) change 事件,event.detail = {current: current, source: source}

注意:其中只可放置<swiper-item/>組件,否則會導(dǎo)致未定義的行為。

swiper-item

注意:僅可放置在<swiper/>組件中,寬高自動設(shè)置為100%。

示例:

<swiper indicator-dots="true"
    autoplay="true" interval="3000" duration="500">
    <block s-for="imgUrl in imgs">
        <swiper-item>
            <image src="{{imgUrl}}" class="slide-image" width="355" height="150"/>
        </swiper-item>
    </block>
</swiper>
Page({
    data: {
        imgs: [
            "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=955704975,2507359007&fm=173&s=32A2DC4D4E12344D4899DCB80300C013&w=218&h=146&img.JPEG",
            "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=984374101,2617012451&fm=173&s=20A24CB176BA0D882C042D700300C092&w=218&h=146&img.JPEG",
            "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1663594687,1286054050&fm=173&s=EAA608C484D2006B5680719A0300E0C1&w=218&h=146&img.JPEG"
        ]
    }
})
Bug & Tip: 1、tip: 如果在 bindchange 的事件回調(diào)函數(shù)中使用 setData 改變 current 值,則有可能導(dǎo)致 setData 被不停地調(diào)用,因而通常情況下請?jiān)诟淖?current 值前檢測 source 字段來判斷是否是由于用戶觸摸引起;

movable-area


解釋:movable-view 的可移動區(qū)域。

注意:movable-area 必須設(shè)置width和height屬性,不設(shè)置默認(rèn)為10px。

movable-view

解釋:可移動的視圖容器,在頁面中可以拖拽滑動。

屬性說明:

屬性名 類型 默認(rèn)值 說明
direction String none movable-view 的移動方向,屬性值有 all 、 vertical 、 horizontal 、 none
inertia Boolean false movable-view 是否帶有慣性
out-of-bounds Boolean false 超過可移動區(qū)域后,movable-view 是否還可以移動
x Number 定義 x 軸方向的偏移,如果 x 的值不在可移動范圍內(nèi),會自動移動到可移動范圍;改變 x 的值會觸發(fā)動畫
y Number 定義 y 軸方向的偏移,如果 y 的值不在可移動范圍內(nèi),會自動移動到可移動范圍;改變 y 的值會觸發(fā)動畫
damping Number 20 阻尼系數(shù),用于控制 x 或 y 改變時的動畫和過界回彈的動畫,值越大移動越快
friction Number 2 摩擦系數(shù),用于控制慣性滑動的動畫,值越大摩擦力越大,滑動越快停止;必須大于 0,否則會被設(shè)置成默認(rèn)值
disabled Boolean false 是否禁用
scale-min Number 0.5 定義縮放倍數(shù)最小值
scale-max Number 10 定義縮放倍數(shù)最大值
scale-value Number 1 定義縮放倍數(shù),取值范圍為 0.5 - 10
bindchange EventHandle 拖動過程中觸發(fā)的事件,event.detail = {x: x, y: y, source: source},其中source表示產(chǎn)生移動的原因,值可為touch(拖動)、out-of-bounds(超出移動范圍后的回彈)、inertia(慣性)和空字符串(setData)

Bug & Tip:

1、movable-view 必須設(shè)置 width 和 height 屬性,不設(shè)置默認(rèn)為 10px;

2、movable-view 默認(rèn)為絕對定位,top 和 left 屬性為 0px;

3、當(dāng)movable-view小于movable-area時,movable-view的移動范圍是在movable-area內(nèi);

4、當(dāng)movable-view大于movable-area時,movable-view的移動范圍必須包含movable-area(x 軸方向和 y 軸方向分開考慮);

注意:movable-view必須在組件中,并且必須是直接子節(jié)點(diǎn),否則不能移動。

示例:


<view class="movable-view">
    <movable-area style="height: 300px;width: 300px;background: green;">
        <movable-view style="height: 40px; width: 40px; background: black;" x="30" y="30" direction="all">
        </movable-view>
    </movable-area>
</view>

cover-view

cover-view


解釋: 覆蓋在原生組件之上的文本視圖,可覆蓋的原生組件包括 video 、 canvas 、 camera,只支持嵌套 cover-view 、 cover-image 。

cover-image

解釋: 覆蓋在原生組件之上的圖片視圖,可覆蓋的原生組件同 cover-view ,支持嵌套在 cover-view 里。

屬性說明:

屬性名 類型 默認(rèn)值 說明
src String 圖標(biāo)路徑,支持臨時路徑、網(wǎng)絡(luò)地址。暫不支持 base64 格式。

Tips:

1、cover-view 支持 overflow: scroll,但不支持動態(tài)更新 overflow。

2、最外層 cover-view 支持 position: fixed。

3、支持 css transition 動畫,transition-property 只支持 transform (translateX, translateY) 與 opacity。

4、文本建議都套上 cover-view 標(biāo)簽,避免排版錯誤。

5、只支持基本的定位、布局、文本樣式。不支持設(shè)置單邊的 border、background-image、shadow、overflow: visible 等。

6、建議子節(jié)點(diǎn)不要溢出父節(jié)點(diǎn)。

7、默認(rèn)設(shè)置的樣式有:white-space: nowrap; line-height: 1.2; display: block 。

8、建議不要頻繁改變 s-if 表達(dá)式的值控制顯隱,否則會導(dǎo)致 cover-view 顯示異常。

示例:


<video id="myVideo"
    src="https://vd3.bdstatic.com/mda-ia8e6q3g23py8qdh/hd/mda-ia8e6q3g23py8qdh.mp4?playlist=%5B%22hd%22%5D&auth_key=1521549485-0-0-d5d042ba3555b2d23909d16a82916ebc&bcevod_channel=searchbox_feed&pd=share" rel="external nofollow" 
    controls>
    <cover-view class="controls">
        <cover-image class="play"
            bindtap="play"
            src="https://smartapp.baidu.com/docs/img/logo.png" rel="external nofollow" >
        </cover-image>
        <cover-view class="pause" bindtap="pause">暫停</cover-view>
        <cover-view class="time">00:00</cover-view>
    </cover-view>
</video>
.controls {
    position: absolute;
    top: 50%;
    width: 100%;
    height: 50px;
    display: flex;
}
.play, .pause, .time {
    flex: 1;
    height: 100%;
    background-color: rgba(0, 0, 0, .5);
}
.pause, .time {
    text-align: center;
    color: white;
    line-height: 50px;
}
cover-image {
    width: 100%;
    height: 100%;
}

Page({
    onReady() {
        this.videoCtx = swan.createVideoContext('myVideo')
    },
    play() {
        this.videoCtx.play()
    },
    pause() {
        this.videoCtx.pause()
    }
})
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號