gpt4 book ai didi

javascript - Timeline JS动态标志颜色变化

转载 作者:行者123 更新时间:2023-11-28 03:34:25 26 4
gpt4 key购买 nike

我在我的应用程序中使用时间轴 JS 来根据日期显示两种类型的报告。它工作正常,但是当报告数据数量较多时,很难找到哪个报告属于哪个类别。所以我想在timemarker中使用不同的文本颜色来区分两种类型。

Type 1. #9467bd
Type 2. #8c651c

但我无法动态设置文本颜色。我引用了时间轴 JS 文档,发现有一个选项可以更改 timemarker - 使用此类名称 .tl-timemarker 的颜色。但我不知道要设置 2 种不同的颜色。 Timeline JS Doc

Timeline JS Sample

JSFiddle Link

请引用我的代码:

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);
}

最佳答案

我不确定我是否完全理解您的任务,但让我试一试。我有一个元素,我需要在事件文本项中混合自定义样式。我确实对 .tl CSS 样式进行了一些自定义(重载),但主要是将 span 标记添加到 JSON 数据,然后通过 CSS 对其进行样式设置。 (见下面的例子)

如果您可以通过代码区分类型 1 和类型 2,则可以将其“模板化”——或者只需为此向 text 项的 JSON 添加一个额外属性。您可以添加任何您想要的属性,时间线代码不在乎。然后你可以使用一些模板库,比如 Handlebarsspan 标签添加到您的 JSON 数据。

JSON

"text": {
"headline": "<span class ='vTime'>00:14:54</span><br>
<span class ='cTime'>00:00:00</span>",
"text": "<span class ='narrative'>Stops swimming.</span>"
}

CSS

.vTime {
font-size: 40px;
line-height: 48px;
color: white;
}

.cTime {
font-size: 40px;
line-height: 48px;
color: yellow;
}

.narrative {
font-size: 26px;
line-height: 30px;
color: white;
}

关于javascript - Timeline JS动态标志颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44565648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com