How to scroll today when "today" button is clickedn in resourceTimelineWeek view
Hi,
While at resourceTimelineWeek view, if user clicks today button, view is scrolled to start of current week. How can I make it to scroll to current day in the week?
Regards
Good question. There is currently no method for such scrolling. I will try to come up with something in future versions.
Maybe it helps somehow: This is what I use as a workaround at the moment for scolling to the current day in Timeline Month for example:
function scrollToDay(containerSelector, todaySelector) { const scrollContainer = document.querySelector(containerSelector); const todayElement = document.querySelector(todaySelector);
if (scrollContainer && todayElement) {
const todayPosition = todayElement.offsetLeft;
scrollContainer.scrollTo({
left: todayPosition,
behavior: 'smooth',
});
} else {
console.error('Scroll container or day element not found.');
}
}
Usage: scrollToToday('.ec-body', '.ec-day.ec-today');
Hi, Personally, I use this function to scroll to the desired date in the resourceTimelineWeek.
scrollTo(date, behavior = 'smooth') {
if (!date) {
return;
}
console.log('Scroll to date:', date);
const intervalId = setInterval(() => {
const targetDateHeaderElement = this.element.querySelector(`.ec-header [datetime="${date}"]`);
if (targetDateHeaderElement) {
const bodyElement = this.element.querySelector('.ec-body');
if (bodyElement) {
const headerRect = targetDateHeaderElement.getBoundingClientRect();
const bodyRect = bodyElement.getBoundingClientRect();
const scrollLeft = headerRect.left - bodyRect.left + bodyElement.scrollLeft;
bodyElement.scrollTo({left: scrollLeft, behavior: behavior});
}
clearInterval(intervalId);
}
}, 100);
}