蛇形时间轴实现

思路: 左中右

html

  <div class="line-box" style="padding-bottom: 30px; flex: 1;">
    <div style="width: 100%; display: flex; position: relative;">
      <!-- 左边 -->
      <div style="width: 10%; margin-left: 30px">
        <div>
          <!-- 开头 -->
          <span
            data-v-jzl20210826=""
            style="margin-top: 95px"
            class="headerRadio"
          ></span>
          <!-- 中间 -->
          <span
            v-for="(it, ii) in ((Index%2===0&&Index>1)?Math.floor(Index/2)-1:Math.floor(Index/2))"
            :key="ii"
            class="hingelisHeard"
            style="margin-top: 190px"
          ></span>
          <!-- 左指箭头 -->
          <span
            data-v-jzl20210826=""
            v-if="Index%2==0"
            style="margin-top: 190.5px; left: 1px"
            class="hingeorgerHeard"
          ></span>
        </div>
      </div>
      <!-- 中间 -->
      <div style="width: 75%">
        <!-- 数据 -->
        <div  v-for="(item, index) in experienceData" :key="index">
          <div style="display:flex;">
            <div
              class="timeline"
              v-for="v in item"
              :key="v.id"
            >
              <div class="border"></div>
              <!-- <div class="Nodes"></div> -->
              <img src="@/assets/client/event/location.png" alt="">
              <div class="timeNodes">
                <p class="nodeTimes">
                  <span :title="v.abstractText">{{ v.abstractText }}</span>
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 右边 -->
      <div style="width: 10%; margin-right: 30px">
        <div>
          <!-- 第一行 -->
          <span class="hingelis" v-if="experienceData.length > 1"></span>
          <span
            data-v-jzl20210826=""
            v-if="experienceData.length<=1"
            class="hingeorger"
          ></span>
          <!-- 第n行中间 -->
          <span
            v-for="(itl, iil) in Index>1?Math.floor(Index/2)-1:0" :key="iil"
            class="hingelis"
            style="margin-top: 190px"
          ></span>
          <!-- 右指箭头 -->
          <span
            data-v-jzl20210826=""
            v-if="(!(Index%2==0))&&Index>1"
            style="margin-top: 190px"
            class="hingeorger"
          ></span>
        </div>
      </div>
    </div>
  </div>

scss

 <style scoped lang="scss">
  .line-box {
    $main-color: #a0bcec;
  
    .timeline {
      width: 100%;
      height: 200px;
      position: relative;
    }
    .border {
      width: 101%;
      border-bottom: 10px solid $main-color;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
     
    .Nodes {
      // width: 8px;
      // height: 8px;
      // background: #fff;
      // position: absolute;
      // right: 35px;
      // top: 50%;
      // -webkit-transform: translate(0, -50%);
      // transform: translate(0, -50%);
      // border-radius: 50%;
    }
    img {
      position: absolute;
      top: 45%;
      -webkit-transform: translate(0, -50%);
      transform: translate(0, -50%);
      right: 65px;
      // right: 30px;
    }
     
    .timeNodes {
      position: absolute;
      right: 0px;
      // right: -30px;
      width: 140px;
      top: 87%;
      transform: translate(0, -80%);
    }
     
    .nodeTimelis {
      width: 70px;
      margin-bottom: 20px;
      margin-left: 20px;
      overflow: hidden;
      word-break: keep-all;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .nodeTimes {
      width: 100%;
      line-height: 1.7;
      background-color: #f5f8fb;
      padding: 3px 10px;
      border-radius: 3px;
      overflow: hidden;
      -webkit-line-clamp: 3;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      font-size: 12px;
      color: #606266;
    }
     
    .hingelis {
      content: "";
      display: block;
      width: 100%;
      height: 210px;
      border: 10px solid $main-color;
      border-radius: 0 50px 50px 0;
      border-left: 0px;
      margin-top: 95px;
    }
     
    .hingelisHeard {
      content: "";
      display: block;
      width: 101%;
      height: 210px;
      border: 10px solid $main-color;
      border-radius: 50px 0 0 50px;
      border-right: 0px;
      margin-top: 50px;
    }
     
    .hingeorger {
      display: block;
      width: 100%;
      border-bottom: 10px solid $main-color;
      margin: 95.1px 0;
      position: relative;
    }
    .hingeorgerHeard {
      display: block;
      width: 100%;
      border-bottom: 10px solid $main-color;
      position: relative;
    }
     
    .hingeorgerHeard[data-v-jzl20210826]:after {
      content: "";
      position: absolute;
      top: -4px;
      left: -12px;
      border-top: 10px solid transparent;
      border-right: 12px solid $main-color;
      border-bottom: 10px solid transparent;
    }
     
    .hingeorger[data-v-jzl20210826]:after {
      content: "";
      position: absolute;
      top: -5px;
      right: -12px;
      border-top: 10px solid transparent;
      border-left: 12px solid $main-color;
      border-bottom: 10px solid transparent;
    }
     
    .headerRadio {
      display: block;
      width: 101%;
      border-bottom: 10px solid $main-color;
      position: relative;
    }
     
    .headerRadio[data-v-jzl20210826]:after {
      // content: "";
      // position: absolute;
      // top: -4px;
      // left: -2px;
      // width: 1px;
      // height: 1px;
      // border-radius: 50%;
      // background: $main-color;
      // border: 5px solid $main-color;
      // position: absolute;
      // right: 35px;
      // top: 50%;
      // transform: translate(0, -50%);
    }
  }
</style>

js

<script>
  export default {
    props: {
      experienceData: { // 在父组件中用toArr处理好的数组
        required: true,
        type: Array
      },
      Index: 0 // 数组experienceData的length
    },
    data () {
      return {
      }
    },
    activated () {
      console.log('dayin', this.experienceData)
    },
    methods: {
      toArr (list) {
        const arr = []
        for (let i=0; i<list.length; i+=3) {
          arr.push(list.slice(i, i+3))
        }
        console.log('arr', arr)
        return arr
      }
    },
    watch: {
      data: function (newVal, oldVal) {
        this.experienceData = newVal
      }
    }
  }
</script>

效果图

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,可以使用HTMLCSS来创建蛇形时间轴的基本结构和样式,然后使用jQuery来操纵它。 下面是一个简单的示例代码: HTML结构: ```html <div class="timeline"> <div class="timeline-item"> <div class="timeline-content"> <h2>2010</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div> <div class="timeline-item"> <div class="timeline-content"> <h2>2012</h2> <p>Donec ut metus eget ligula blandit commodo.</p> </div> </div> <div class="timeline-item"> <div class="timeline-content"> <h2>2015</h2> <p>Suspendisse potenti. Nulla facilisi.</p> </div> </div> <div class="timeline-item"> <div class="timeline-content"> <h2>2018</h2> <p>Phasellus vel semper velit, eget varius ex.</p> </div> </div> </div> ``` CSS样式: ```css .timeline { position: relative; margin: 0 auto; padding: 0; list-style: none; max-width: 800px; } .timeline:before { content: ''; position: absolute; top: 0; bottom: 0; width: 2px; background-color: #ddd; left: 50%; margin-left: -1px; } .timeline-item { margin-bottom: 50px; position: relative; } .timeline-item:before, .timeline-item:after { content: ''; display: table; } .timeline-item:after { clear: both; } .timeline-item:last-child { margin-bottom: 0; } .timeline-content { position: relative; width: 50%; padding: 20px; background-color: #f7f7f7; border-radius: 8px; } .timeline-content h2 { margin-top: 0; } .timeline-content p { margin: 0; } /* 反转偶数项 */ .timeline-item:nth-child(even) .timeline-content { float: right; } .timeline-item:nth-child(even) .timeline-content:before { right: auto; left: -15px; border-width: 8px 0 8px 15px; border-color: transparent transparent transparent #f7f7f7; } .timeline-item:nth-child(even) .timeline-content:after { right: auto; left: 0px; border-width: 7px 0 7px 15px; border-color: transparent transparent transparent #ddd; } ``` jQuery代码: ```javascript $(document).ready(function() { var items = $('.timeline-item'); var heights = []; // 获取所有项目的高度 items.each(function() { var height = $(this).outerHeight(); heights.push(height); }); // 设置所有项目的高度 items.each(function(i) { var height = heights[i]; $(this).css('height', height); }); }); ``` 这段代码将获取所有时间轴项目的高度,并将其应用到每个项目上,从而创建一个蛇形时间轴的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值