2012-09-28 112 views
1

我一直使用从here与JSON版本的数据retreival TimelineJS。它工作正常,但我无法调整时间线开始的日期。时间轴JS:如何设置时间轴开始日期?

在文档它说,设立JSON文件为这样:只用

{ 
    "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":"" 
       } 
      }, 

我曾尝试:

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

我复制了这一点,但只是改变的细节,如在startDate年(例如:2011年)也没有效果。时间线从下面的第一个事件开始。

任何人都知道发生了什么事?

感谢

+0

我也有与Timeline.js问题。我无法让事情做到甚至可以工作。 –

回答

2

我还没有找到一种方法来直接指定时间表的开始日期,但你可以遍历你的时间表滑动以找到最接近的匹配,然后使用该幻灯片的指数作为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 
}); 
+0

感谢您的创新理念。 –

+1

仅供参考,以下是直接链接到TimelineJS的配置选项(特别是“幻灯片开始”属性):https://github.com/NUKnightLab/TimelineJS#start-at-slide –