如何更改 Vis.js 时间线,使其始终关注当前时间标记(红线),以便我知道时间线中现在正在发生什么。根据我的缩放级别或距离,时间线应向左或向右平移并聚焦于当前时间指示器。
我在这里考虑两个选项:要么运行一个 setInterval() 每 15 分钟更新并关注当前时间,要么在页面上设置一个按钮来手动执行此操作。
根据我的研究,到目前为止,我发现它与按钮绑定(bind),显然还不起作用:
document.getElementById('focusNow').onclick = function() {
timeline.focus(timeline.currentTime.bar)
};
最佳答案
我知道这是一个老问题,但我能够像这样解决它:
var refresh = 10000;
timeline = new vis.Timeline(container, data, options);
function updateTimeline(refresh) {
setTimeout(function(){
var current = new Date();
timeline.moveTo(current);
updateTimeline(refresh)
}, refresh);
}
updateTimeline(refresh);
updateTimeline 函数每 10 秒运行一次,并移动时间线,使当前时间居中(使用 moveTo() 函数),从而使红线保持居中。一旦我的项目完成,我将使用 github 链接进行更新。
关于javascript - Vis.js 关注当前时间(红线),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36223720/