Categories: ElementPlus 教程

ElementPlus Affix 固钉

Affix 固钉

将页面元素固定在特定可视区域。

基本用法

固钉默认固定在页面顶部。

通过设置 offset 属性来改变吸顶距离,默认值为 0。

<template>
  <el-affix :offset="120">
  <el-button type="primary">距离顶部 120px</el-button>
</el-affix>
</template>

指定容器

通过设置 target 属性,让固钉始终保持在容器内,超过范围则隐藏。

请注意容器避免出现滚动条。

<template>
  <div class="affix-container">
  <el-affix target=".affix-container" :offset="80">
    <el-button type="primary">指定容器</el-button>
  </el-affix>
</div>
</template>

固定位置

Affix 组件提供了两个固定位置:top 和 bottom。

通过设置 position 属性来改变固定位置,默认值为 top 。

<template>
  <el-affix position="bottom" :offset="20">
  <el-button type="primary">距离底部 20px</el-button>
</el-affix>
</template>

Attributes

参数 说明 类型 可选值 默认值
offset 偏移距离 number 0
position 固钉位置 string top / bottom top
target 指定容器(CSS 选择器) string
z-index 固钉层级 number 100

Events

事件名称 说明 回调参数
change 固钉状态改变时触发的事件 (value: boolean)
scroll 滚动时触发的事件 滚动距离和固钉状态

Methods

方法名 说明 参数
update 手动更新固钉状态

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

vue:页面注入js修改input值

一般会直接这样写: let z…

3 小时 ago

聊聊vue3中的defineProps

在Vue 3中,defineP…

1 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

1 月 ago