CSS实现一个动态横向时间轴

CSS实现一个动态横向时间轴

先看效果


html

<template>
  <x-view class="stepFlex">
    <x-view
      v-for="(item, index) in testList"
      :key="index"
      style="position: relative; flex: 1; text-align: center;margin-top:-10px"
    >
      <x-view >{{ item.name }}</x-view>
      <x-view
        :class="item.ceshi == '1' ? 'greenCircle' :item.ceshi == '2' ? 'now' : 'greyCircle'"
      ></x-view>  
      <x-view
        v-if="index !== testList.length - 1"
        :class="testList[index + 1].ceshi != '3' ? 'greenline' : 'greyline'"
      ></x-view>
      <x-view style="margin-top:20px">{{ item.time }}</x-view>
    </x-view>
  </x-view>
</template>

css

.stepFlex {
  display: flex;
  .greenCircle {
    top: calc(50% - 4px);
    left: calc(50% - 4px);
    position: absolute;
    z-index: 2;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #08d0c3;
  }
  .now{
    top: calc(50% - 8px);
    left: calc(50% - 8px);
    position: absolute;
    z-index: 3;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #08d0c3;
    border: 4px solid #cef6f3;
  }
  .greyCircle {
    top: calc(50% - 4px);
    left: calc(50% - 4px);
    position: absolute;
    z-index: 2;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc;
  }

  .greenline {
    width: 100%;
    top: calc(50% - 2px);
    left: calc(50% - 2px);
    height: 2px;
    background-color: #08d0c3;
    position: absolute;
  }

  .greyline {
    height: 0;
    border: 1px dashed #ccc;
    width: 100%;
    top: calc(50% - 2px);
    left: calc(50% - 2px);
    position: absolute;
  }
}

js

testList:[{
      name:'购买',
      time:'2019/01/25',
      ceshi:1
    },
    {
      name:'起息',
      time:'2019/01/25',
      ceshi:2
    },{
      name:'到期',
      time:'2019/01/25',
      ceshi:3
    }],
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用HTML5和CSS实现横向时间轴特效,具体实现步骤如下: 1. 首先,使用HTML创建一个时间轴容器,其中包含一个无序列表(ul)和多个列表项(li),每个列表项表示一个时间节点。 2. 使用CSS设置时间轴容器的宽度和高度,并将列表项的display属性设置为inline-block,以便它们在同一水平线上显示。 3. 通过CSS设置每个列表项的宽度、高度、背景色、边框、圆角等样式属性,以便它们具有时间轴的外观。 4. 使用CSS设置每个列表项的位置,使它们在时间轴上按照时间顺序排列。可以使用position属性将它们定位在时间轴上。 5. 为了实现鼠标悬停效果,可以使用CSS设置每个列表项的:hover样式属性。例如,可以改变背景颜色或添加阴影效果。 6. 最后,通过CSS添加动画效果来实现时间轴的滑动效果。可以使用transition或animation属性来实现。 下面是一个示例代码,实现一个简单的横向时间轴特效: ``` <!DOCTYPE html> <html> <head> <style> .timeline { width: 800px; height: 100px; margin: 0 auto; position: relative; background-color: #f2f2f2; border-radius: 10px; overflow: hidden; } .timeline li { display: inline-block; width: 100px; height: 100px; background-color: #fff; border: 1px solid #ccc; border-radius: 50%; position: absolute; bottom: 0; transform: translateY(50%); transition: all 0.3s ease-in-out; } .timeline li:hover { background-color: #f2f2f2; box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.5); } .timeline li:nth-child(odd) { left: 50%; transform: translateX(-50%) translateY(50%); } .timeline li:nth-child(even) { right: 50%; transform: translateX(50%) translateY(50%); } .timeline:hover li { transform: translateY(-50%); } </style> </head> <body> <div class="timeline"> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </body> </html> ``` 在这个示例中,我们创建了一个名为“timeline”的容器,其中包含了一个无序列表。我们使用CSS设置了容器的宽度、高度、背景色和边框等样式属性。列表项具有圆形形状,并使用CSS设置了它们的位置和样式属性。 我们还添加了一个:hover样式属性,以便在鼠标悬停时改变列表项的背景颜色和添加阴影效果。最后,我们使用CSS添加了一个动画效果,使时间轴在鼠标悬停时滑动。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值