fix autoscroll
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 5m26s
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 5m26s
This commit is contained in:
parent
a9dc145514
commit
12e4f08a6a
2 changed files with 26 additions and 10 deletions
|
|
@ -82,7 +82,7 @@ pub fn build_timetables(
|
||||||
});
|
});
|
||||||
|
|
||||||
for trip in direction_trips.clone() {
|
for trip in direction_trips.clone() {
|
||||||
if let Some(last) = trip.schedule.last() {
|
if let Some(last) = trip.schedule.iter().max_by_key(|x| x.arrival_time) {
|
||||||
if next_id == None && i64::from(seconds_since_midnight) < last.arrival_time {
|
if next_id == None && i64::from(seconds_since_midnight) < last.arrival_time {
|
||||||
next_id = Some(last.trip_id.clone());
|
next_id = Some(last.trip_id.clone());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,33 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
document.querySelectorAll("details[data-direction-id]").forEach(details => {
|
const scrollToNextColumn = (directionId) => {
|
||||||
details.addEventListener("toggle", () => {
|
|
||||||
if (details.open) {
|
|
||||||
// Delay scroll until DOM is expanded/rendered
|
|
||||||
setTimeout(() => {
|
|
||||||
const directionId = details.getAttribute("data-direction-id");
|
|
||||||
const target = document.getElementById("next-col-" + directionId);
|
const target = document.getElementById("next-col-" + directionId);
|
||||||
if (target) {
|
if (target) {
|
||||||
target.scrollIntoView({ behavior: "smooth", inline: "start", block: "nearest" });
|
const scrollContainer = target.closest(".tscroll");
|
||||||
|
const firstCol = scrollContainer.querySelector("th:first-child");
|
||||||
|
const firstColWidth = firstCol ? firstCol.offsetWidth : 0;
|
||||||
|
|
||||||
|
// Get the target's position relative to the scroll container
|
||||||
|
const targetLeft = target.offsetLeft;
|
||||||
|
|
||||||
|
// Scroll so the target appears right after the sticky column
|
||||||
|
scrollContainer.scrollLeft = targetLeft - firstColWidth;
|
||||||
}
|
}
|
||||||
}, 50); // Short delay to allow rendering
|
};
|
||||||
|
|
||||||
|
document.querySelectorAll("details[data-direction-id]").forEach(details => {
|
||||||
|
const directionId = details.getAttribute("data-direction-id");
|
||||||
|
|
||||||
|
// Scroll immediately if details is already open
|
||||||
|
if (details.open) {
|
||||||
|
setTimeout(() => scrollToNextColumn(directionId), 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also scroll when details is opened
|
||||||
|
details.addEventListener("toggle", () => {
|
||||||
|
if (details.open) {
|
||||||
|
setTimeout(() => scrollToNextColumn(directionId), 50);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue