Vue sample code for implementing two-column horizontal timeline

Vue sample code for implementing two-column horizontal timeline

This article mainly introduces the sample code of Vue to realize two-column horizontal timeline, which is shared with you as follows:

First, let's take a look at the picture. It mainly implements a two-column horizontal timeline. I looked at what many people have implemented, and there is only one horizontal column. Moreover, the timeline of elementUI is only vertical and does not support horizontal. In the end, I could only implement it myself with tears. I didn't expect it to be okay. However, if there is a lot of data, page turning has not been implemented yet. Friends who have implemented this can tag me.

1. Implement the component timelineH.vue

The H in timelineH.vue stands for horizontal. It’s hard to name it, haha.

<template>
    <ul class="timelineHengBox">
        <li class="timelineHengItem" v-for="(item,index) in timelineList" :key="index" 
            :style="{left: index % 2 != 0 ? (liHalf*index)+52+'px':0,'border-right': index == timelineList.length - 2 ?'1px solid #FEFEFE' : 'none'}">
            <div class="timeline_dot" :style="{top: index % 2 != 0 ? '-5px' : '93px'}"></div>
            <div class="timeline_dot" v-show="index == timelineList.length - 2" style="right: -6px;top:93px;left: unset;"></div>
            <div class="timeline_wapper flex" :class="{'mt20': ​​index % 2 != 0}">
                <img src="../../static/img/excelIcon.png" class="bjIcon" :style="{'margin': index % 2 != 0 ? '11px 44px 0 42px' :''}">
                <div>{{item.content}}</div>
            </div>
            <div class="timelineDate_bottom" :style="{'top': index % 2 != 0 ? '-20px' : '103px'}">{{item.dateTime}}</div>
        </li>
    </ul>
</template>

<script>
    export default {
        name: 'timelineH',
        props: {
            timelineList: {
                type: Array,
                default: []
            }
        },
        data () {
            return {
                liWidth: 496, //The width of the entire li, to be consistent with the style of the li below liHalf: 248, //This is half the width of the li, so that the point on the middle horizontal line can find the correct position}
        }
    }
</script>
<style scoped>
    .timelineHengBox {
        color: #fff;
        margin: 0;
        padding: 0 26px;
        width: 92%;
        padding-top: 18px;
        padding-bottom: 10px;
        margin-left: 26px;
        height: 87px;
        border-bottom: 3px solid #FEFEFE;
    }
    .timelineHengItem {
        list-style: none;
        height: 97px;
        width: 496px;
        border-left: 1px solid #FEFEFE;
        float: left;
        border-bottom: 3px solid #FEFEFE;
        position: relative;
    }
    .timelineHengItem:nth-child(2n) {
        position: absolute;
        left: 248px;
        border-bottom: 0;
        top: 115px;
    }
    .timeline_dot {
        width: 10px;
        height: 11px;
        background: #FEFEFE;
        position: absolute;
        left: -5px;
        top: 93px;
    }
    .timeline_dot:nth-child(2n) {
        top: -7px;
    }
    .timeline_wapper {
        width: 400px;
        text-align: left;
        font-size: 12px;
        color: #FFFFFF;
        line-height: 20px;
    }
    .mt20 {
        margin-top: 20px;
    }
    .bjIcon {
        width: 32px;
        height: 32px;
        margin: 31px 44px 0 42px;
    }
    .timelineDate_bottom {
        width: 80px;
        height: 20px;
        position: absolute;
        top: 103px;
        left: -60px;
        text-align: left;
        font-size: 14px;
        font-weight: bold;
        color: #FFBA00;
        margin-left: 77px;
    }
</style>

Implementation ideas:

  • The vertical line is realized by setting the left border of li. The main thing here is to put every second li in the middle of the previous li, so half of the entire width of the li should be set using absolute positioning left, and the distance from the top should also be calculated.
  • The blocks at each time point are realized by absolute positioning. It should be noted that the nodes in the upper column and the nodes in the lower column have different distances from the top, so I used CSS: nth-child (2n) to achieve the top distance of every second li.
  • Finally, the date node text is used to determine the odd and even numbers of li and set different top values.
  • Because there is no page turning function, the length of li needs to be adapted or the width of li needs to be reduced if the amount of data is large, otherwise it will look ugly if the amount of data is large. There is no optimization for the time being, but if it is to adapt to laptops, it can still be achieved by modifying the width of li and lihalf.

2. Calling Components

<div class="timelineHengContainer">
     <timelineH :timelineList='timelineList' />
</div>

js:

import timelineH from "@/components/timelineH.vue";
components:
        timelineH
},

data() {
    return {
          timelineList: [

                {
                    dateTime: '2021-09',
                    content: 'Welcome to mining, mine every day and get ore, hahahaha, welcome to mining, mine every day and get ore, hahahaha, welcome to mining, mine every day and get ore, hahahaha, welcome to mining, mine every day and get ore, hahahaha. '
                },{
                    dateTime: '2021-10',
                    content: 'Please keep warm in winter, it's too cold.Please keep warm in winter, it's too cold.Please keep warm in winter, it's too cold.Please keep warm in winter, it's too cold. '
                },{
                    dateTime: '2021-11',
                    content: 'The thirty-day post challenge has officially begun. I want a projector. I've always wanted to buy one. '
                },{
                    dateTime: '2021-12',
                    content: 'It's almost the end of the month, a new year begins, happy new year, a new year begins, happy new year, a new year begins, happy new year. '
                }
            ]
    }
}

css:

.timelineHengContainer {
        width: 100%;
        height: 227px;
        background-image: url('../../static/img/timelineBg.png');
        background-size: 100% 100%;
        background-repeat: no-repeat;
}

OK, this has realized the timeline with two horizontal columns. You can copy the code and use it directly (using the CV method~). I spent two days on it. I referred to the method of drawing the vertical timeline of elementui, but failed. I also failed to implement it with pure div and css. The main reason was that I didn’t know how to draw the vertical lines of the two columns and the nodes. Finally, I thought of using li to directly add a border to achieve it.

This is the end of this article about the sample code for implementing a two-column horizontal timeline in Vue. For more relevant Vue two-column horizontal timeline content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue implements horizontal timeline
  • Vue implements timeline function
  • VUE implements timeline playback component
  • How to draw the timeline with vue+canvas
  • Vue.js implements timeline function
  • Vue+swiper realizes timeline effect
  • Vue realizes the logistics timeline effect
  • Vue timeline vue-light-timeline usage instructions
  • Vue implements movable horizontal timeline
  • Vue implements timeline effect

<<:  IE8 browser will be fully compatible with Web page standards

>>:  How to implement the King of Glory matching personnel loading page with CSS3

Recommend

React event binding details

Table of contents Class component event binding F...

Docker uses busybox to create a base image

The first line of a Docker image starts with an i...

MySQL cross-table query and cross-table update

Friends who have some basic knowledge of SQL must...

React and Redux array processing explanation

This article will introduce some commonly used ar...

Detailed discussion of several methods for deduplicating JavaScript arrays

Table of contents 1. Set Deduplication 2. Double ...

Introduction to reactive function toRef function ref function in Vue3

Table of contents Reactive Function usage: toRef ...

In-depth understanding of the role of Vuex

Table of contents Overview How to share data betw...

Specific use of MySQL window functions

Table of contents 1. What is a window function? 1...

Summary of the application of transition components in Vue projects

​Transtion in vue is an animation transition enca...

MySQL 8.0.20 winx64 installation and configuration method graphic tutorial

This article shares with you the installation and...

MySQL EXPLAIN statement usage examples

Table of contents 1. Usage 2. Output results 1.id...

About the problem of offline installation of Docker package on CentOS 8.4

The virtual machine used is CentOS 8.4, which sim...

Implementation of CSS3 button border animation

First look at the effect: html <a href="#...

How to quickly paginate MySQL data volumes of tens of millions

Preface In backend development, in order to preve...