当前位置: 首页 > news >正文

vue3+flex动态的绘制蛇形时间轴

蛇形时间轴

  • 实现思路
  • 视图代码
  • 逻辑代码
  • 样式代码

实现思路

蛇形排列,奇数列设定左边框,偶数列设定右边框且内容反转显示
激活的色调为蓝,否则为灰
行-列-当前激活可以动态设定
在这里插入图片描述

视图代码

<template><div class="timelinebox"><!-- 行设置,奇数行设置左边框,偶数行设置右边框,为了实现蛇形排列,偶数行需反转显示 --><!-- 经过的时间轴变蓝,未过为灰 根据激活的值为行动态的添加.on的class样式, --><div class="timeline" v-for="row in rows" :key="row":class="{ 'reverse': row % 2 === 0, 'on': row - 1 < activeIndex / cols }"><!-- 列设置,动态的计算列宽 改变激活的颜色,动态的添加.active --><div class="timelineItem" v-for="item in cols" :key="item":class="{ 'active': (row - 1) * cols + item <= activeIndex }" :style="{ width: (100 / cols) + '%' }"><!-- 文本的标题一行,显示不下的... 注意子元素必须绝对定位,父相对定位,否则...不起作用,且错位乱版 --><div class="itemTitle"><div class="ellipsis">{{ (row - 1) * cols + item }}项的标题<span v-if="row > 1 && row < 4">内容细节与详情</span></div></div><div class="itemDot"></div></div></div></div>
</template>

逻辑代码

<script setup>
// 行数
let rows = 13
// 列数
let cols = 6
// 当前激活的数 等于当前行数-1*列数+当前列数
let activeIndex = 10
</script>

样式代码

<style scoped lang="scss">
.timelinebox {width: 100%;height: 100%;padding: 20px;box-sizing: border-box;display: block;position: relative;overflow-y: auto;.timeline {width: 100%;height: 80px;display: flex;justify-content: start;border-left: 5px solid gray;.timelineItem {height: 100%;border-bottom: 5px solid gray;display: flex;flex-direction: column;justify-content: end;align-items: center;cursor: default;position: relative;.itemTitle {position: absolute;bottom: 10px;left: 0px;width: 100%;box-sizing: border-box;padding: 10px;text-align: center;font-size: 18px;overflow: hidden;}.itemDot {width: 20px;height: 20px;background-color: gray;border-radius: 10px;margin-bottom: -12px;display: block;}}.timelineItem.active {border-color: blue;.itemTitle {color: blue;}.itemDot {background-color: blue;}}}.timeline.reverse {flex-direction: row-reverse;justify-content: end;border-right: 5px solid gray;border-left: 0px;}.timeline.on {border-color: blue;}.timeline:first-child {border: 0}
}
</style>

相关文章:

  • Python小程序:上班该做点摸鱼的事情
  • vue3+Nest.js项目 部署阿里云
  • 字节跳动社招面经 —— BSP驱动工程师(4)
  • vue.js中的一些事件修饰符【前端】
  • uni-app 中封装全局音频播放器
  • 深入蜂窝物联网 第四章 Cat-1 与 5G RedCap:带宽、低时延与未来趋势
  • 五、UI自动化测试05--PyTest框架
  • 【SpringBoot】基于MybatisPlus的博客管理系统(1)
  • 【Unity】使用Socket建立客户端和服务端并进行通信的例子
  • 东土科技NewPre系列智能控制器的创新之旅
  • VMware安装 银河麒麟操作系统桌面版 V10 SP1 2403
  • HotSpot的算法细节
  • 集群系统的五大核心挑战与困境解析
  • 4月28号
  • 漏洞复现清单整理-预备梳理,等待补充
  • 多维驱动:负载均衡何以成为现代系统架构的基石
  • 网络爬取需谨慎:警惕迷宫陷阱
  • Ansible安装配置
  • 代发考试战报:4月份 思科认证,华为认证,考试战报分享
  • Twitter 工作原理|架构解析|社交APP逻辑
  • 解放日报:这是一场需要定力和实力的“科技长征”
  • 李铁案二审今日宣判
  • 中使馆:奉劝菲方有关人士不要在台湾问题上挑衅,玩火者必自焚
  • 央行召开落实金融“五篇大文章”总体统计制度动员部署会议
  • 怒江州委常委、泸水市委书记余剑锋调任云南省委省直机关工委副书记
  • 一周人物|卡鲁等入围英国特纳奖,李学明新展中国美术馆