简体   繁体   中英

Auto scroll fullcalendar V5( resourceTimelineWeek View) to current date and time

I am using Fullcalendar V5. While trying to set the scrollTime to the current date and time in the resourceTimelineWeek view, time only is working fine, but how shall I set the date scrolling.

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
}
)};

Now, it is 09:30 and the time is showing correctly. But the date is Oct 01, which is still Sep 27 on the calendar scroll view. 只工作时间

Tested on FullCalendar 5.8.0 (using jQuery and 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);
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM