javascript - 时间轴 JS : How to set timeline start date?

标签 javascript jquery json jquery-plugins

我一直在使用 here 的 TimelineJS使用 JSON 版本的数据检索。它工作正常,但我无法调整时间线的开始日期。

在文档中它说要这样设置 JSON 文件:

    {
        "timeline":
        {
            "headline":"The Main Timeline Headline Goes here",
            "type":"default",
            "startDate":"1888",
            "text":"<p>Intro body text goes here, some HTML is ok</p>",

我已经复制了这个但只是更改了细节,例如:

{
    "timeline":
    {
        "headline":"HOT LATIN EVENTS",
        "type":"default",
        "startDate":"2012,09,30",
        "text":"Scroll through a list of Latin Music events>>> ",
        "date": [

             {
                "startDate":"2012,08,24",
                "headline":"PELIGRO Y SU BANDA  - Melbourne",
                "text":"<p><strong>Copacaban International</strong>, 139 Smith Street, Fitzroy, 3065</p>",
                "asset":
                {
                    "media":"http://www.clavecontraclave.com/Peligro%20-%20Melbourne%20klein.jpg",
                    "credit":"",
                    "caption":""
                }
            },

我也尝试在 startDate 中使用一年(例如:2011 年)但没有效果。时间线从下面的第一个事件开始。

有人知道这是怎么回事吗?

谢谢

最佳答案

我还没有找到直接指定时间线开始日期的方法,但您可以遍历时间线幻灯片以找到最接近的匹配项,然后使用该幻灯片的索引作为您的 start_at_slide 值。例如:

var timeline_dates = data_source.timeline.date;
var start_index = 0;
var target_date = new Date(); //set whatever date you want as your start date
for(x in timeline_dates) {
    var slide_date = new Date( timeline_dates[x].startDate );
    if( slide_date < target_date) start_index++;
}

然后当你实例化你的时间线时,你会像这样使用它:

createStoryJS({
    type:       'timeline',
    width:      '800',
    height:     '400',
    source:     data_source,
    embed_id:   'timeline_container',
    start_at_slide: start_index
});

关于javascript - 时间轴 JS : How to set timeline start date?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12632085/

相关文章:

javascript - 如何搜索具有多个值的单个单元格

javascript - Netsuite 外部 URL 调用

javascript - 使按钮关闭一个 div(使用 Wordpress)

javascript - javascript中函数的并行执行

javascript - 如何在某人的网站上构建一个小部件并托管在您的网站上?

javascript - 将数据从 PHP 应用程序传递到 JS 的正确方法是什么?

Javascript,通过服务器将字符串提交到 JSON 文件,换行符不起作用

javascript - ReactJs 换时间视频html5

javascript - 如何避免 mailto 的烦恼?

java - 如何在 TextView 中设置格式化的 JSON 响应字符串?