2012-09-28 57 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 –