当前打开日期的中心 Vis.js 时间线

use*_*026 6 javascript vis.js vis.js-timeline

我有一个从 2017 年 1 月到 2018 年的 VisJS 时间线。时间线以年中三个月的范围为中心打开,但我希望它每次都以当前时间为中心打开。

min: new Date(2017, 1, 5),           // lower limit of visible range
max: new Date(2018, 1, 11),          // upper limit of visible range
zoomMin: 1000 * 60 * 60 * 24,        // one day in milliseconds
zoomMax: 1000 * 60 * 60 * 24*31*3,   // three months in milliseconds
Run Code Online (Sandbox Code Playgroud)

Luk*_*ela 5

你可以试试这样的(timeline.setWindow()):

const todayStart = new Date();
todayStart.setHours(8, 0, 0, 0);
const todayEnd = new Date();
todayEnd.setHours(18, 0, 0, 0);

console.log(todayStart, ':', todayEnd);
setTimeout(_ => {
  this.timeline.setWindow(todayStart, todayEnd, { animation: true });
});
Run Code Online (Sandbox Code Playgroud)

或者更好 moveTo

  this.timeline.moveTo(new Date());//or
  this.timeline.moveTo(new Date(), { animation: true });//or
  this.timeline.moveTo(new Date(), { animation: true }, (props) => {
    console.log("movedTo", props);
  });
Run Code Online (Sandbox Code Playgroud)