Scroll current song into view when song changes

This commit is contained in:
Sijmen 2024-01-05 05:19:40 +01:00
parent 29103c1c8a
commit 25889df62e
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48

View file

@ -25,6 +25,14 @@
</ul>
<script>
const scrollCurrentSongIntoView = () => {
const hoveredSong = document.querySelector(".queue li:hover");
if (hoveredSong === null) {
const currentSong = document.querySelector(".queue li.playing");
currentSong.scrollIntoView({ block: "nearest" });
}
}
htmx.onLoad(() => {
const isReduced = window
.matchMedia("(prefers-reduced-motion: reduce)")
@ -38,5 +46,7 @@ htmx.onLoad(() => {
body: JSON.stringify({from: event.oldIndex, to: event.newIndex}),
}),
});
scrollCurrentSongIntoView();
});
</script>