请原谅标题用词奇怪,我不太确定该如何提出问题,因此希望我在下面的说明会有所帮助。
我们的团队需要使用angularjs开发水平时间线,该时间线还可以正确缩放时间。我们在Codepen上遇到的许多时间表中,每个事件的间隔都是相等的。我们需要建立一个时间表来相应地调整事件日期。我们遇到的最接近的时间表是Codyhouse,但是我们不能使用jquery。
//Sample dates
var dates = ["6/12/2015", "8/15/2015", "10/22/2015", "11/2/2015", "12/22/2015"];
//For the purpose of stringifying MM/DD/YYYY date format
var monthSpan = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
//Format MM/DD/YYYY into string
function dateSpan(date) {
var month = date.split('/')[0];
month = monthSpan[month - 1];
var day = date.split('/')[1];
if (day.charAt(0) == '0') {
day = day.charAt(1);
}
var year = date.split('/')[2];
//Spit it out!
return month + " " + day + ", " + year;
}
//Main function. Draw your circles.
function makeCircles() {
//Forget the timeline if there's only one date. Who needs it!?
if (dates.length < 2) {
$("#line").hide();
$("#span").show().text(dateSpan(dates[0]));
//This is what you really want.
} else if (dates.length >= 2) {
//Set day, month and year variables for the math
var first = dates[0];
var last = dates[dates.length - 1];
var firstMonth = parseInt(first.split('/')[0]);
var firstDay = parseInt(first.split('/')[1]);
var lastMonth = parseInt(last.split('/')[0]);
var lastDay = parseInt(last.split('/')[1]);
//Integer representation of the last day. The first day is represnted as 0
var lastInt = ((lastMonth - firstMonth) * 30) + (lastDay - firstDay);
//Draw first date circle
$("#line").append('<div class="circle" id="circle0" style="left: ' + 0 + '%;"><div class="popupSpan">' + dateSpan(dates[0]) + '</div></div>');
$("#mainCont").append('<span id="span0" class="center">' + dateSpan(dates[0]) + '</span>');
//Loop through middle dates
for (i = 1; i < dates.length - 1; i++) {
var thisMonth = parseInt(dates[i].split('/')[0]);
var thisDay = parseInt(dates[i].split('/')[1]);
//Integer representation of the date
var thisInt = ((thisMonth - firstMonth) * 30) + (thisDay - firstDay);
//Integer relative to the first and last dates
var relativeInt = thisInt / lastInt;
//Draw the date circle
$("#line").append('<div class="circle" id="circle' + i + '" style="left: ' + relativeInt * 100 + '%;"><div class="popupSpan">' + dateSpan(dates[i]) + '</div></div>');
$("#mainCont").append('<span id="span' + i + '" class="right">' + dateSpan(dates[i]) + '</span>');
}
//Draw the last date circle
$("#line").append('<div class="circle" id="circle' + i + '" style="left: ' + 99 + '%;"><div class="popupSpan">' + dateSpan(dates[dates.length - 1]) + '</div></div>');
$("#mainCont").append('<span id="span' + i + '" class="right">' + dateSpan(dates[i]) + '</span>');
}
$(".circle:first").addClass("active");
}
makeCircles();
$(".circle").mouseenter(function() {
$(this).addClass("hover");
});
$(".circle").mouseleave(function() {
$(this).removeClass("hover");
});
$(".circle").click(function() {
var spanNum = $(this).attr("id");
selectDate(spanNum);
});
function selectDate(selector) {
$selector = "#" + selector;
$spanSelector = $selector.replace("circle", "span");
var current = $selector.replace("circle", "");
$(".active").removeClass("active");
$($selector).addClass("active");
if ($($spanSelector).hasClass("right")) {
$(".center").removeClass("center").addClass("left")
$($spanSelector).addClass("center");
$($spanSelector).removeClass("right")
} else if ($($spanSelector).hasClass("left")) {
$(".center").removeClass("center").addClass("right");
$($spanSelector).addClass("center");
$($spanSelector).removeClass("left");
};
};
console.log()
* {
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background: #e97162;
font-family: Arial;
overflow: hidden;
}
#lineCont {
width: 100%;
height: 20%;
}
#line {
height: 6px;
width: 70%;
background: white;
border-radius: 5px;
margin: auto;
top: 50%;
transform: translateY(-50%);
position: relative;
}
#span {
display: none;
width: 70%;
margin: auto;
margin-top: 25%;
text-align: center;
color: white;
}
.circle {
width: 20px;
height: 20px;
background: #e97162;
border-radius: 15px;
position: absolute;
top: -7px;
border: 3px solid white;
cursor: pointer;
}
.circle:before {
content: '';
width: 10px;
height: 10px;
background: white;
position: absolute;
border-radius: 100%;
top: 2px;
left: 2px;
display: none;
}
.circle .popupSpan {
width: auto;
height: auto;
padding: 10px;
white-space: nowrap;
display: inline-block;
color: white;
position: absolute;
top: 20px;
left: -75px;
display: none;
transition: all 0.1s ease-out;
}
.circle.hover:before, .circle.active:before {
display: block;
}
.circle.hover .popupSpan, .circle.active .popupSpan {
display: block;
}
.circle.active .popupSpan {
top: -40px;
}
#mainCont {
height: 80%;
width: 100%;
position: relative;
color: white;
font-size: 62px;
text-align: center;
transition: all 0.2s ease-out;
}
#mainCont span {
display: inline-block;
width: 100%;
height: 100%;
position: absolute;
top: 30%;
transition: all 0.2s ease-out;
}
#mainCont span.right {
left: 200%;
}
#mainCont span.center {
left: 0% !important;
}
#mainCont span.left {
left: -100%;
}
<div id="lineCont">
<div id="line"></div>
<div id="span">Date Placeholder</div>
</div>
<div id="mainCont">
</div>
是否有一个现有的库在angularjs中执行此操作?如果没有,关于如何实现此目标的任何建议?例如,我们如何重构诸如this之类的时间轴,以考虑时间和日期?
/* Timeline */
.timeline,
.timeline-horizontal {
list-style: none;
padding: 20px;
position: relative;
}
.timeline:before {
top: 40px;
bottom: 0;
position: absolute;
content: " ";
width: 3px;
background-color: #eeeeee;
left: 50%;
margin-left: -1.5px;
}
.timeline .timeline-item {
margin-bottom: 20px;
position: relative;
}
.timeline .timeline-item:before,
.timeline .timeline-item:after {
content: "";
display: table;
}
.timeline .timeline-item:after {
clear: both;
}
.timeline .timeline-item .timeline-badge {
color: #fff;
width: 54px;
height: 54px;
line-height: 52px;
font-size: 22px;
text-align: center;
position: absolute;
top: 18px;
left: 50%;
margin-left: -25px;
background-color: #333;
border: 3px solid #ffffff;
z-index: 100;
border-top-right-radius: 50%;
border-top-left-radius: 50%;
border-bottom-right-radius: 50%;
border-bottom-left-radius: 50%;
}
.timeline .timeline-item .timeline-badge i,
.timeline .timeline-item .timeline-badge .fa,
.timeline .timeline-item .timeline-badge .glyphicon {
top: 2px;
left: 0px;
}
.timeline .timeline-item .timeline-badge.primary {
background-color: #1f9eba;
}
.timeline .timeline-item .timeline-badge.info {
background-color: #5bc0de;
}
.timeline .timeline-item .timeline-badge.success {
background-color: #59ba1f;
}
.timeline .timeline-item .timeline-badge.warning {
background-color: #d1bd10;
}
.timeline .timeline-item .timeline-badge.danger {
background-color: #ba1f1f;
}
.timeline .timeline-item .timeline-panel {
position: relative;
width: 46%;
float: left;
right: 16px;
border: 1px solid #777;
background: #ffffff;
border-radius: 2px;
padding: 20px;
-webkit-box-shadow: 0 1px 6px rgba(0, 0, 0, 0.175);
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.175);
}
.timeline .timeline-item .timeline-panel:before {
position: absolute;
top: 26px;
right: -16px;
display: inline-block;
border-top: 16px solid transparent;
border-left: 16px solid #777;
border-right: 0 solid #777;
border-bottom: 16px solid transparent;
content: " ";
}
.timeline .timeline-item .timeline-panel .timeline-title {
margin-top: 0;
color: inherit;
}
.timeline .timeline-item .timeline-panel .timeline-body > p,
.timeline .timeline-item .timeline-panel .timeline-body > ul {
margin-bottom: 0;
}
.timeline .timeline-item .timeline-panel .timeline-body > p + p {
margin-top: 5px;
}
.timeline .timeline-item:last-child:nth-child(even) {
float: right;
}
.timeline .timeline-item:nth-child(even) .timeline-panel {
float: right;
left: 16px;
}
.timeline .timeline-item:nth-child(even) .timeline-panel:before {
border-left-width: 0;
border-right-width: 14px;
left: -14px;
right: auto;
}
.timeline-horizontal {
list-style: none;
position: relative;
padding: 20px 0px 20px 0px;
display: inline-block;
}
.timeline-horizontal:before {
height: 3px;
top: auto;
bottom: 26px;
left: 56px;
right: 0;
width: 100%;
margin-bottom: 20px;
}
.timeline-horizontal .timeline-item {
display: table-cell;
height: 280px;
width: 20%;
min-width: 320px;
float: none !important;
padding-left: 0px;
padding-right: 20px;
margin: 0 auto;
vertical-align: bottom;
}
.timeline-horizontal .timeline-item .timeline-panel {
top: auto;
bottom: 64px;
display: inline-block;
float: none !important;
left: 0 !important;
right: 0 !important;
width: 100%;
margin-bottom: 20px;
}
.timeline-horizontal .timeline-item .timeline-panel:before {
top: auto;
bottom: -16px;
left: 28px !important;
right: auto;
border-right: 16px solid transparent !important;
border-top: 16px solid #777 !important;
border-bottom: 0 solid #777 !important;
border-left: 16px solid transparent !important;
}
.timeline-horizontal .timeline-item:before,
.timeline-horizontal .timeline-item:after {
display: none;
}
.timeline-horizontal .timeline-item .timeline-badge {
top: auto;
bottom: 0px;
left: 43px;
}
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Horizontal timeline</h1>
</div>
<div style="display:inline-block;width:100%;overflow-y:auto;">
<ul class="timeline timeline-horizontal">
<li class="timeline-item">
<div class="timeline-badge primary"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 1</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis faiz elementum girarzis, nisi eros gostis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge success"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 2</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis faiz elementum girarzis, nisi eros gostis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge info"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 3</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipisci. Mé faiz elementum girarzis, nisi eros gostis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge danger"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 4</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge warning"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 5</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 6</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis.</p>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Timeline</h1>
</div>
<ul class="timeline">
<li class="timeline-item">
<div class="timeline-badge"><i class="glyphicon glyphicon-off"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 1</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros vermeio, in elementis mé pra quem é amistosis quis leo. Manduma pindureta quium dia nois paga. Sapien in monti palavris qui num significa nadis i pareci latim. Interessantiss quisso pudia ce receita de bolis, mais bolis eu num gostis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 2</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros gostis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 3</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros vermeio, in elementis mé pra quem é amistosis quis leo. Manduma pindureta quium dia nois paga. Sapien in monti palavris qui num significa nadis i pareci latim. Interessantiss quisso pudia ce receita de bolis, mais bolis eu num gostis.</p>
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros vermeio, in elementis mé pra quem é amistosis quis leo. Manduma pindureta quium dia nois paga. Sapien in monti palavris qui num significa nadis i pareci latim. Interessantiss quisso pudia ce receita de bolis, mais bolis eu num gostis.</p>
</div>
</div>
</li>
<li class="timeline-item">
<div class="timeline-badge"><i class="glyphicon glyphicon-check"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Mussum ipsum cacilds 4</h4>
<p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago via Twitter</small></p>
</div>
<div class="timeline-body">
<p>Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros vermeio, in elementis mé pra quem é amistosis quis leo. Manduma pindureta quium dia nois paga. Sapien in monti palavris qui num significa nadis i pareci latim. Interessantiss quisso pudia ce receita de bolis, mais bolis eu num gostis.</p>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
谢谢!