我有一个从 2017 年 1 月到 2018 年 1 月的 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
最佳答案
你可以试试这样的东西(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 });
});
或更好的
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);
});
关于javascript - 打开当前日期的中心 Vis.js 时间线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46611598/