vue3项目之Affix 固钉固定定位

文章介绍了如何使用ElementPlus的Affix组件来实现网页元素的固定定位。通过设置offset属性,可以设定元素距离顶部固定的触发距离。同时,通过指定target,可以让元素在特定容器内进行固定。示例代码展示了如何创建一个在滚动到特定位置后固定在顶部120px的按钮,以及如何在特定容器内固定元素。
摘要由CSDN通过智能技术生成

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cocoonne

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值