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

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>
http://www.xdnf.cn/news/3181.html

相关文章:

  • 远程桌面导致Quartus 破解失效
  • Silvaco仿真中的victory mesh
  • 【MySQL数据库】--1.安装教程
  • HHsuite同源序列搜索数据库构建
  • 如何在Windows中更改文档默认打开方式
  • 【保姆级教程-Centos7环境下部署Prometheus并设置开机自启】
  • 【Yolo精读+实践+魔改系列】Yolov2论文超详细精讲(翻译+笔记)
  • temu,shein采购测评避坑指南:如何避免砍单封号,实现长效运营?
  • Harbor默认Redis与Notary组件弱口令漏洞分析与修复指南
  • ​【空间数据分析】缓冲区分析--泰森多边形(Voronoi Diagram)-arcgis操作
  • labview项目文件架构
  • WSL2下Docker desktop的Cadvisor容器监控
  • Spring Security 的 CSRF 防护机制
  • 时态--09--动词过去式、过去分词
  • 搜索——哈希优化策略
  • MTK Genio500 移植GMS及youtube问题处理的解决办法
  • docker拉取国内镜像
  • Javascript 中的继承?如何实现继承?
  • 解密Cloak斗篷技术:FP独立站推广利器
  • [论文阅读]Adversarial Semantic Collisions
  • 为什么要学习《易经》?
  • 大模型核心技术及架构解析
  • Android Q允许低内存启用系统弹窗
  • 蓝桥杯算法开发企业级实战指导:从0到1的C/C++全攻略
  • kubelet 清理资源以缓解磁盘压力
  • 考OCM证书前需要有OCP证书
  • 再谈cookie和session(结合表白墙具体案例)
  • 第一讲 | 算法复杂度
  • Jmeter接口自动化测试读取用例
  • 软件设计师-软考知识复习(2)