如何解决自动将全日历V5resourceTimelineWeek View滚动到当前日期和时间
我正在使用Fullcalendar V5。尝试在resourceTimelineWeek视图中将scrollTime设置为当前日期和时间时,只有时间工作正常,但是如何设置日期滚动。
var scrollTime = moment().format("HH") + ":00:00";
document.addEventListener('DOMContentLoaded',function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl,{
now: new Date(),scrollTime: scrollTime
}
)};
现在是09:30,时间显示正确。但是日期是10月1日,在日历滚动视图上仍然是9月27日。
解决方法
在 FullCalendar 5.8.0 上测试(使用 jQuery 和 moment.js)
options = {
datesSet: ({ view }) => {
if (view.type === 'resourceTimelineWeek') {
const scroller = $('.fc-scrollgrid-section-body .fc-scroller').last();
const [date] = moment().toISOString().split(':');
const position = $(`.fc-timeline-slot[data-date^="${date}"]`).last().position();
if (position) {
scroller.scrollLeft(position.left);
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。