W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Sticky 組件與 CSS 中position: sticky屬性實(shí)現(xiàn)的效果一致,當(dāng)組件在屏幕范圍內(nèi)時(shí),會(huì)按照正常的布局排列,當(dāng)組件滾出屏幕范圍時(shí),始終會(huì)固定在屏幕頂部。
import Vue from 'vue';
import { Sticky } from 'vant';
Vue.use(Sticky);
將內(nèi)容包裹在Sticky組件內(nèi)即可
<van-sticky>
<van-button type="primary">基礎(chǔ)用法</van-button>
</van-sticky>
通過(guò)offset-top屬性可以設(shè)置組件在吸頂時(shí)與頂部的距離
<van-sticky :offset-top="50">
<van-button type="info">吸頂距離</van-button>
</van-sticky>
通過(guò)container屬性可以指定組件的容器,頁(yè)面滾動(dòng)時(shí),組件會(huì)始終保持在容器范圍內(nèi),當(dāng)組件即將超出容器底部時(shí),會(huì)固定在容器的底部
<div ref="container" style="height: 150px;">
<van-sticky :container="container">
<van-button type="warning">指定容器</van-button>
</van-sticky>
</div>
export default {
data() {
return {
container: null
};
},
mounted() {
this.container = this.$refs.container;
}
};
參數(shù) | 說(shuō)明 | 類(lèi)型 | 默認(rèn)值 |
---|---|---|---|
offset-top | 吸頂時(shí)與頂部的距離,單位px | number | string | 0 |
z-index | 吸頂時(shí)的 z-index | number | string | 99 |
container | 容器對(duì)應(yīng)的 HTML 節(jié)點(diǎn) | Element | - |
事件名 | 說(shuō)明 | 回調(diào)參數(shù) |
---|---|---|
scroll | 滾動(dòng)時(shí)觸發(fā) | { scrollTop: 距離頂部位置, isFixed: 是否吸頂 } |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: