2017-08-24 109 views

回答

0

哦,我忘了關閉這個問題。 有可悲的是這種沒有API,但一個簡單的超時會做。

setTimeout(function() { 
    //do stuff on appointment begin 
    setTimeout(function() { 
     //do something when finished 
    }, end - Date.now()); 
}, start - now); 

Ps。你必須爲每個約會做這件事。

0

好,紅線就是當前時間。你可以有一個時間間隔,比方說,3秒鐘,並檢查是否有任何時間線的任何項目通過線路。像這樣的僞代碼:

var timeline = ... // This is the timeline object 

setInterval(function() { 
    var now = new Date(); // This is the current position of the timeline 
    for (var d in timeline.itemsData._data) { 
     if (d.start <= now && d.end >= now) { // this means the red line is crossing this item 
      // do something... 
     } 
    } 
}, 3); // each 3 seconds 

代碼不完整。但有一個主要想法。

+0

我不建議這樣做 –

+0

你能告訴我爲什麼嗎?此外,它似乎比你的解決方案的方式清潔... –

+0

輪詢是不是一個好主意 –

相關問題