【发布时间】:2017-06-15 10:52:42
【问题描述】:
我在我的应用程序中使用时间轴 JS 来根据日期显示 2 种类型的报告。它工作正常,但是当报告数据的数量更多时,很难找到哪个报告属于哪个类别。所以我想在 timemarker 中使用不同的文本颜色来区分两种类型。
Type 1. #9467bd
Type 2. #8c651c
但我无法动态设置文本颜色。我参考了时间线 JS 文档,发现有一个选项可以通过使用此类名称 .tl-timemarker 来更改 timemarker - 颜色。但我不知道设置两种不同的颜色。Timeline JS Doc
请参考我的代码:
HTML 代码:
<div id="my-timeline"></div>
<button id='myBtn'>start</button>
JS 代码:
$('#myBtn').click(function() {
var data = {
"timeline":
{
"headline":"Test Company",
"type":"default",
"text":"Test Reports",
"startDate":"2010",
"date": [
{
"startDate" : "2010,9,1",
"text":"Type 1",
"headline":"Test Header",
"asset":
{
"media": "PDF link",
"credit": "View Doc",
"caption":"Caption text goes here"
}
},
{
"startDate":"2011,10,12",
"text":"Type 2",
"headline":"Test Header",
"asset":
{
"media": "PDF link",
"credit": "View Doc",
"caption": ""
}
},
{
"startDate":"2011,10,12",
"text":"Type 2",
"headline":"Test Header",
"asset":
{
"media": "PDF link",
"credit": "View Doc",
"caption": ""
}
},
{
"startDate":"2011,10,12",
"text":"Type 2",
"headline":"Test Header",
"asset":
{
"media": "PDF link",
"credit": "View Doc",
"caption": ""
}
},
{
"startDate":"2011,10,12",
"text":"Type 1",
"headline":"Test Header",
"asset":
{
"media": "PDF link",
"credit": "View Doc",
"caption": ""
}
},
{
"startDate":"2011,10,12",
"text":"Type 2",
"headline":"Test Header",
"asset":
{
"media": "PDF link",
"credit": "View Doc",
"caption": ""
}
}
]
}
};
loadData(JSON.stringify(data));
});
function loadData(json){
addCode('jsFile='+json);
createStoryJS({
type: 'timeline',
width: '800',
height: '600',
source: jsFile,
embed_id: 'my-timeline'
});
}
//addCode(code) will create a script element and add code to it
function addCode(code){
var JS= document.createElement('script');
JS.text= code;
document.body.appendChild(JS);
}
【问题讨论】:
标签: javascript jquery css timeline.js