W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
將頁(yè)面元素固定在特定可視區(qū)域。
固釘默認(rèn)固定在頁(yè)面頂部。
通過(guò)設(shè)置 offset 屬性來(lái)改變吸頂距離,默認(rèn)值為 0。
<template>
<el-affix :offset="120">
<el-button type="primary">距離頂部 120px</el-button>
</el-affix>
</template>
通過(guò)設(shè)置 target 屬性,讓固釘始終保持在容器內(nèi),超過(guò)范圍則隱藏。
請(qǐng)注意容器避免出現(xiàn)滾動(dòng)條。
<template>
<div class="affix-container">
<el-affix target=".affix-container" :offset="80">
<el-button type="primary">指定容器</el-button>
</el-affix>
</div>
</template>
Affix 組件提供了兩個(gè)固定位置:top 和 bottom。
通過(guò)設(shè)置 position 屬性來(lái)改變固定位置,默認(rèn)值為 top 。
<template>
<el-affix position="bottom" :offset="20">
<el-button type="primary">距離底部 20px</el-button>
</el-affix>
</template>
參數(shù) | 說(shuō)明 | 類型 | 可選值 | 默認(rèn)值 |
---|---|---|---|---|
offset | 偏移距離 | number | — | 0 |
position | 固釘位置 | string | top / bottom | top |
target | 指定容器(CSS 選擇器) | string | — | — |
z-index | 固釘層級(jí) | number | — | 100 |
事件名稱 | 說(shuō)明 | 回調(diào)參數(shù) |
---|---|---|
change | 固釘狀態(tài)改變時(shí)觸發(fā)的事件 | (value: boolean) |
scroll | 滾動(dòng)時(shí)觸發(fā)的事件 | 滾動(dòng)距離和固釘狀態(tài) |
方法名 | 說(shuō)明 | 參數(shù) |
---|---|---|
update | 手動(dòng)更新固釘狀態(tài) | — |
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)系方式:
更多建議: