Affix 固钉固定定位
官网:https://element-plus.gitee.io/zh-CN/component/affix.html
先将元素样式位置写好,然后外面再套一层 el-affix
即可!实现当页面滑到该元素位置时即可实现固定效果
<template>
<el-affix :offset="120">
<el-button type="primary">Offset top 120px</el-button>
</el-affix>
</template>
offset
:固定到顶部的距离
还可以设置只在盒子中固定的效果
<template>
<div class="affix-container">
<el-affix target=".affix-container" :offset="80">
<el-button type="primary">Target container</el-button>
</el-affix>
</div>
</template>
<style scoped>
.affix-container {
text-align: center;
height: 400px;
border-radius: 4px;
background: var(--el-color-primary-light-9);
}
</style>