html实现会拐弯的时间线,jquery实现会拐弯的时间线,css实现会拐弯的时间线

前言

jquery + html + css实现一个会拐弯的时间线
基于此网址整改,参考:https://www.jq22.com/webqd5873

效果

在这里插入图片描述

实现

基于jQuery,需要引入jQuery.js,没有必要使用太高版本,够用就行
jquery下载:https://www.jb51.net/zt/jquerydown.htm

html中

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" href="css/timeLine.css" />
	</head>

	<body>

		<div class="clearfix time-wrapper"></div>
		<div style="padding: 20px;margin-top: 100px">
			<p>输入数量,生成时间线</p>
			<input type="number" class="test" value="0">
			<button id="btn">生成</button>
		</div>

	</body>
	<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="js/timeLine.js"></script>

</html>

css中

* {
	word-wrap:break-word
}
html,body,h1,h2,h3,h4,h5,h6,hr,p,,dl,dt,dd,ul,ol,li,pre,form,button,input,textarea,th,td,fieldset {
	margin:0;
	padding:0
}
ul,ol,dl {
	list-style-type:none
}
html,body {
	*position:static
}
html {
	font-family:sans-serif;
	-webkit-text-size-adjust:100%;
	-ms-text-size-adjust:100%
}
address,caption,cite,code,dfn,em,th,var {
	font-style:normal;
	font-weight:400
}
input,button,textarea,select,optgroup,option {
	font-family:inherit;
	font-size:inherit;
	font-style:inherit;
	font-weight:inherit
}
input,button {
	overflow:visible;
	vertical-align:middle;
	outline:none
}
body,th,td,button,input,select,textarea {
	font-family:"Microsoft Yahei","Hiragino Sans GB","Helvetica Neue",Helvetica,tahoma,arial,Verdana,sans-serif,"WenQuanYi Micro Hei","\5B8B\4F53";
	font-size:14px;
	color:#333;
	-webkit-font-smoothing:antialiased;
	-moz-osx-font-smoothing:grayscale
}
h1,h2,h3,h4,h5,h6 {
	font-size:100%
}
a,area {
	outline:none;
	blr:expression(this.=this.blur())
}
a {
	text-decoration:none;
	cursor:pointer
}
a:hover {
	text-decoration:underline;
	outline:none
}
a.ie6:hover {
	zoom:1
}
a:focus {
	outline:none
}
a:hover,a:active {
	outline:none
}
:focus {
	outline:none
}
sub,sup {
	vertical-align:baseline
}
button,input[type="button"],input[type="submit"] {
	line-height:normal !important
}
/*img*/
img {
	border:0;
	vertical-align:middle
}
a img,img {
	-ms-interpolation-mode:bicubic
}
.img-responsive {
	max-width:100%;
	height:auto
}
/*IE下a:hover 背景闪烁*/
*html {
	overflow:-moz-scrollbars-vertical;
	zoom:expression(function(ele) {
	ele.style.zoom = "1";
	document.execCommand("BackgroundImageCache",false,true)
}
(this))}/*HTML5 reset*/
header,footer,section,aside,details,menu,article,section,nav,address,hgroup,figure,figcaption,legend {
	display:block;
	margin:0;
	padding:0
}
time {
	display:inline
}
audio,canvas,video {
	display:inline-block;
	*display:inline;
	*zoom:1
}
audio:not([controls]) {
	display:none
}
legend {
	width:100%;
	margin-bottom:20px;
	font-size:21px;
	line-height:40px;
	border:0;
	border-bottom:1px solid #e5e5e5
}
legend small {
	font-size:15px;
	color:#999
}
svg:not(:root) {
	overflow:hidden
}
fieldset {
	border-width:0;
	padding:0.35em 0.625em 0.75em;
	margin:0 2px;
	border:1px solid #c0c0c0
}
input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button {
	height:auto
}
input[type="search"] {
	-webkit-appearance:textfield;
	/* 1 */-moz-box-sizing:content-box;
	-webkit-box-sizing:content-box;
	/* 2 */box-sizing:content-box
}
input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration {
	-webkit-appearance:none
}
/*
Name:style_clearfix
Example:class="clearfix|cl"
Explain:Clearfix(简写cl)避免因子元素浮动而导致的父元素高度缺失能问题
*/
table {
	border-collapse:collapse;
	border-spacing:0;
}
input:hover {
	border:1px solid #067BBB!important;
}
input:focus {
	border:1px solid #067BBB;
	outline:0;
}
.cl:after,.clearfix:after {
	content:".";
	display:block;
	height:0;
	clear:both;
	visibility:hidden
}
.cl,.clearfix {
	zoom:1
}
.btn {
	border:none;
	border-radius:4px;
	cursor:pointer;
}
.form-control {
	display:inline-block;
	width:100%;
	height:34px;
	margin:0 auto;
	box-sizing:border-box;
	padding:6px 12px;
	font-size:14px;
	line-height:34px;
	color:#555;
	background-color:#fff;
	background-image:none;
	border:1px solid #ccc;
	border-radius:4px;
	-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);
	box-shadow:inset 0 1px 1px rgba(0,0,0,.075);
	-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
	-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;
	transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
.btn-primary {
	background:rgb(46,117,183);
	color:#FFFFFF;
}
.btn-primary:hover {
	background:rgba(46,117,183,0.8);
}
.btn-default {
	background:#FFFFFF;
	border:1px solid #c9c9c9;
}
.left {
	float:left;
}
.right {
	float:right;
}
.time-wrapper {
	width:100%;
	padding:40px 60px;
	padding-top:100px;
	box-sizing:border-box;
}
.time-wrapper>div {
	width:100%;
	position:relative;
	margin-top:-2px;
}
.time-wrapper>div.first-group {
	margin-top:80px;
}
.odd-group .left-arrow {
	display:none;
	min-height:190px;
}
.odd-group .right-arrow {
	min-height:190px;
}
.even-group .right-arrow {
	display:none;
	min-height:190px;
}
.right-arrow {
	width: 190px;
    border-top-right-radius: 50%;
    border-bottom-right-radius: 50%;
	border:2px solid #597dff;
	border-left:none;
	min-height:130px;
	box-sizing:border-box;
	float:right;
	position: relative;
    right: -58px;
}
.left-arrow {
	width: 190px;
    border-top-left-radius: 50%;
    border-bottom-left-radius: 50%;
	border:2px solid #597dff;
	border-right:none;
	min-height:130px;
	box-sizing:border-box;
	float:left;
	position: relative;
    left: -58px;
}
.even-group .left-arrow {
	min-height:190px;
}
.odd-group .time-detail {
	position:absolute;
	left:30px;
	right:30px;
	top:-122px;
}
.even-group .time-detail {
	position:absolute;
	left:30px;
	right:30px;
	top: -122px;
}
.g-line {
	height:2px;
	background:#597dff;
	position:absolute;
	left:30px;
	right:30px;
	top:0;
}
.time-detail .detail-c {
	width:20%;
	box-sizing:border-box;
	float:left;
	position:relative;
	padding:0 10px;
}
.floatRight .detail-c {
	float:right;
}
.time-detail .detail-c .circle {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #597dff;
    box-sizing: border-box;
    position: absolute;
    z-index: 99;
    background: #ffffff;
    bottom: -18px;
    top: auto;
}
.odd-group .circle {
	bottom:-19px;
}
.even-group .circle {
	top:-18px;
}
.time-detail .detail-c .circle .circle-son {
	width:6px;
	height:6px;
	border-radius:50%;
	background:#597dff;
	box-sizing:border-box;
	margin:2px;
}
.detail-m {
    max-width: 100%;
    display: inline-block;
    padding: 10px;
    background: #fbfbfb;
    box-sizing: border-box;
    border-radius: 5px;
    height: 110px;
   	background: #fff;
    box-shadow: #00000015 0 2px 5px 0;
}
.detail-m h3 {
	font-weight:bold;
}
.detail-m p {
	overflow:hidden;
	text-overflow:ellipsis;
	white-space:nowrap;
}
.floatLeft .detail-c {
	float:left;
}
.disappear {
	display:none!important;
}

js中

$(function() {
    timeLine(6);
    $("#btn").click(function() {
        timeLine($(".test").val())
    })
})

function timeLine(num) {
    var timeHtml = '';
    var numUp = Math.ceil(num / 5);
    for (var i = 0; i < numUp; i++) {
        if ((i + 1) % 2 == 1 && i == 0) {
            timeHtml += '<div class="odd-group floatLeft first-group clearfix">'
        } else if ((i + 1) % 2 == 1) {
            timeHtml += '<div class="odd-group floatLeft clearfix">'
        } else {
            timeHtml += '<div class="even-group floatRight clearfix">'
        }
        timeHtml += '<div class="left-arrow"></div><div class="g-line"></div><div class="right-arrow"></div><div class="time-detail clearfix">'
        for (var j = 5 * i; j < 5 * (i + 1); j++) {
            if (j < num) {
                timeHtml += '<div class="detail-c">' +
                    '<div class="detail-m">' +
                    '<h3>' + (j + 1) + '</h3>' +
                    '<p>这里可以填充你需要的内容 (。・ω・。)ノ♡</p>' +
                    '</div>' +
                    '<div class="circle">' +
                    '<div class="circle-son"></div>' +
                    '</div>' +
                    '</div>'
            }
        }
        timeHtml += '</div></div>'
    }
    $(".time-wrapper").html(timeHtml);
    if ($(".time-wrapper>div:last-child").hasClass("even-group")) {
        $(".time-wrapper>div:last-child").find(".left-arrow").hide()
    } else if ($(".time-wrapper>div:first-child").hasClass("odd-group")) {
        $(".time-wrapper>div:last-child").find(".right-arrow").hide()
    }
    var circle = $(".circle");
    $(circle[0]).children(".circle-son").hide();
    $(circle[circle.length - 1]).children(".circle-son").hide();
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3 Timeline 时间线实现拐弯时间轴相对于普通的时间线来说更加有趣和独特。在实现这种时间轴时,我们可以使用 Vue3 的组件化开发方式来创建一个可重复使用的时间线组件。 首先,我们需要创建一个 TimeNode(时间节点)组件,用来表示每个时间点。我们可以为每个节点设置一个时间和一个事件描述。时间节点可以通过计算属性或者接收传递的属性来设定其位置。 接下来,在时间线组件中,我们需要创建一个数组来存储时间节点。我们可以使用 v-for 指令来遍历这个数组,并将每个时间节点渲染到视图中。 然后,我们可以使用 CSS 来为时间节点添加样式,使其能够正确地显示出拐弯的效果。我们可以为时间节点设置不同的样式类,然后在 CSS 中定义这些样式类的样式规则,来实现时间轴的拐弯效果。 最后,我们可以根据时间节点的数量和位置,计算出时间轴的长度和位置,然后通过 CSS 来设置时间轴的样式,使其正确地显示出拐弯时间轴效果。 通过以上的步骤,我们就可以实现一个拐弯时间轴组件。这个组件可以根据需要接收传递的属性,可以根据时间节点的数量和位置来自动计算出时间轴的样式,使其能够正确地显示出拐弯的效果。 总之,Vue3 Timeline 时间线实现拐弯时间轴,通过使用 Vue3 的组件化开发方式,结合计算属性、遍历数组、添加样式和计算位置等技巧,可以比较容易地实现出一个有趣和独特的时间轴组件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值