• ant design vue:自定义锚点样式


    要做一个如下图的锚点,ant design vue的锚点样式比较简单,按照官网文档:affix="false" :showInkInFixed="true",就可以显示小方块,但是我试了一下不管用,而且锚点组件不固定起来很不方便,所以放弃这种方法。

    之后想过用时间轴和步骤条来模拟锚点,样式很容易达到如图效果,但是在锚点定位上要做太多改造,还是放弃了这种方法。

    仔细研究锚点文档,发现可以通过插槽自定义标题,那么想要在文字前面加图标就很简单了。

    1. <a-anchor @change="onchange">
    2. <template v-for="(item,index) in items">
    3. <a-anchor-link :href="'#'+index" @click="onclick(index)">
    4. <template #title>
    5. <EnvironmentFilled :style="{fontSize: '16px', color: '#1677ff'}" v-if="index==currentIndex"/>
    6. <span class="grayBall" v-else>span>
    7. <span :class="index==currentIndex?'active':''">{{item.title}}span>
    8. template>
    9. a-anchor-link>
    10. template>
    11. a-anchor>

    在文字前面加了图标后,如下图:

    css样式上还需要改动,去掉蓝色小条,并且将灰色竖线往右移到图标的中间去,样式如果不生效,就加!important。

    1. // 隐藏默认的蓝色竖条
    2. ::v-deep .ant-anchor .ant-anchor-ink {
    3. display: none!important;
    4. }
    5. // 将灰色竖线移到图标中间
    6. ::v-deep .ant-anchor:before {
    7. left: 25px!important;
    8. }

    完整代码:

     最终效果:

  • 相关阅读:
    vue中如何动态绑定高度
    DOM
    select完成服务器并发
    联合特征增强和网络参数优化的人脸识别方法
    [附源码]SSM计算机毕业设计郴职图书馆管理系统JAVA
    Java 百度智能云(身份证识别)
    Gateway 整合 Sentinel 实现网关限流
    LeetCode每日一题——1582. 二进制矩阵中的特殊位置
    2023二建建筑施工备考第二天Day06水泥
    减轻压力保护脊椎,上学路上更轻松,Deuter多特护脊减负双肩背包体验
  • 原文地址:https://blog.csdn.net/lilycheng1986/article/details/133875449