Vue2时间轴(横向)

简介: 该横向时间轴组件 `HorizonTimeLine` 可自定义时间轴数据 (`timelineData`) 和初始选中年份 (`activeYear`)。通过点击不同的年份,可以改变当前激活的年份,并有相应的视觉反馈。该组件支持均匀自适应排列,且易于在其他页面中引入和使用。

可自定义设置以下属性:

  • 时间轴数据(timelineData),必传
  • 初始选中年份(activeYear),默认2020

效果如下图(自适应均匀排列,每个元素周围分配相同的空间):

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAdGhlTXVzZUNhdGNoZXI=,size_20,color_FFFFFF,t_70,g_se,x_16

①创建横向时间轴组件HorizonTimeLine.vue:

<template>
  <div class="m-timeline-wrap">
    <div class="m-time-dot">
      <div
        :class="['m-dot-box', {'active': active===item.year}]"
        @click="onClickYear(item.year)"
        v-for="(item, index) in timelineData"
        :key="index">
        <p class="u-year">{
  
  { item.year }}</p>
        <div class="m-dot">
          <div class="u-dot"></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'HorizonTimeLine',
  props: {
    timelineData: { // 时间轴数据
      type: Array,
      required: true,
      default: () => {
        return []
      }
    },
    activeYear: { // 初始选中年份
      type: Number,
      default: 2020
    }
  },
  data () {
    return {
      active: this.activeYear
    }
  },
  methods: {
    onClickYear (year) {
      if (this.active !== year) {
        this.active = year
        console.log('hello', year)
      }
    }
  }
}
</script>
<style lang="less" scoped>
@themeColor: #1890FF;
.m-timeline-wrap {
  margin: 150px auto;
  height: 3px;
  background: #8dc6f5;
  .m-time-dot {
    display: flex;
    justify-content: space-around;
    .m-dot-box {
      cursor: pointer;
      text-align: center;
      transform: translateY(-100%+14px);
      .u-year {
        font-size: 28px;
        font-weight: 500;
        color: #333;
        transform: translateY(-8px);
        transition: all 0.3s ease;
      }
      .m-dot {
        margin: 0 auto;
        width: 14px;
        height: 14px;
        background: #8dc6f5;
        border-radius: 50%;
        transition: all 0.3s ease;
        .u-dot {
          width: 14px;
          height: 14px;
          background: #8dc6f5;
          border-radius: 50%;
          transition: all 0.3s ease;
        }
      }
    }
    .m-dot-box:hover {
      .u-year {
        color: @themeColor;
      }
      .m-dot {
        .u-dot {
          background: @themeColor;
        }
      }
    }
    .active {
      .u-year {
        transform: scale(2) translateY(-18px); // 同时设置多个transform属性只需用空格间隔,执行时从后往前执行!
        color: @themeColor;
      }
      .m-dot {
        transform: scale(3);
        .u-dot {
          transform: scale(0.67);
          background: @themeColor;
        }
      }
    }
  }
}
</style>

②在要使用的页面引入:

<HorizonTimeLine :timelineData="timelineData" :activeYear="2021" />
import HorizonTimeLine from '@/components/HorizonTimeLine'
components: {
  HorizonTimeLine
}
timelineData: [
  {
    year: 2022
  },
  {
    year: 2021
  },
  {
    year: 2020
  },
  {
    year: 2019
  },
  {
    year: 2018
  }
]
相关文章
|
移动开发 JavaScript 前端开发
分享46个JS时间轴特效,总有一款适合您
分享46个JS时间轴特效,总有一款适合您
442 2
|
JSON JavaScript API
【开源打印组件】vue-plugin-hiprint初体验
本文介绍对vue-plugin-hiprint部分重要代码的解析,这是一个很好的开源插件,能够自己自定义打印模板,通过后端传来的数据进行渲染打印,官方也提供了许多的api供开发者使用。界面采用了antdesign。实现了免预览的直接打印。
4418 1
【开源打印组件】vue-plugin-hiprint初体验
|
JavaScript
Vue自定义组件实现类似elementUI的append-to-body功能,将创建的元素插入、挂载到body上面(网页最外层),适用于父元素overflow: hidden、绝对定位fixed的场景
Vue自定义组件实现类似elementUI的append-to-body功能,将创建的元素插入、挂载到body上面(网页最外层),适用于父元素overflow: hidden、绝对定位fixed的场景
Vue2时间轴(Timeline)
本文介绍了一个基于 Vue3 的时间轴组件 `Timeline`,允许用户自定义时间轴宽度和描述文本。通过在 `Timeline.vue` 中使用模板、脚本及样式代码,文章展示了如何创建并使用该组件,并提供了示例代码以供参考。
1288 2
Vue2时间轴(Timeline)
Vue2步骤条(Steps)
这是一个基于 Vue3 的步骤条(Steps)组件,支持高度自定义。主要属性包括步骤标题数组(stepsLabel)、步骤描述数组(stepsDesc)、步骤总数(totalSteps,默认为3)、当前选中的步骤(currentStep,默认为1)、步骤条总宽度(totalWidth,默认为900px)和描述文本最大宽度(descMaxWidth,默认为140px)。组件通过不同的样式展示已完成、进行中和未开始的状态,并支持点击切换步骤。可在需要的页面中引入并传入相关初始数据。
457 1
Vue2步骤条(Steps)
|
11月前
|
JSON JavaScript 数据格式
jqtimeline.js-简单又好用的jquery时间轴插件
jqtimeline.js-简单又好用的jquery时间轴插件
Vue3时间轴(Timeline)
这是一个基于 Vue2 的时间轴(Timeline)组件,支持多种自定义属性,包括时间轴内容数组 `timelineData`、总宽度 `width`、线条样式 `lineStyle`、模式 `mode` 和位置 `position`。时间轴内容数组包含描述 `desc` 和圆圈颜色 `color`。组件提供了丰富的样式选项,如虚线、居中显示等,并支持内容交替展现。适用于多种场景下的时间轴展示需求。
1524 1
Vue3时间轴(Timeline)
|
JavaScript API 容器
Vue3气泡卡片(Popover)
这是一个基于Vue的气泡卡片组件(Popover)介绍,提供了在线预览链接及详细API参数说明,包括maxWidth、title、content等,并支持自定义样式。
717 0
Vue3气泡卡片(Popover)
|
JavaScript
vue2中左侧菜单和头部tab标签联动
vue2中左侧菜单和头部tab标签联动
647 0
|
数据可视化 定位技术
【threejs】可视化大屏酷炫3D地图附源码
【threejs】可视化大屏酷炫3D地图附源码
12140 131
【threejs】可视化大屏酷炫3D地图附源码