Skip to content

Commit

Permalink
Use native scrolling for lyrics
Browse files Browse the repository at this point in the history
- On mouse wheel scroll, disable autoscrolling until remounted
  • Loading branch information
jaedb committed Jan 3, 2024
1 parent 9b74d9b commit 35e1eb2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 15 additions & 3 deletions src/js/views/Modals/KioskMode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import Modal from './Modal';
import Thumbnail from '../../components/Thumbnail';
Expand All @@ -17,12 +17,24 @@ const LyricsScroller = ({
content = '',
percent = 0,
}) => {
const containerRef = useRef({});
const contentRef = useRef({});
const [autoScroll, setAutoScroll] = useState(true);
const onWheel = () => setAutoScroll(false);

useEffect(() => {
if (autoScroll) {
const scrollable = contentRef.current?.scrollHeight - containerRef.current.clientHeight;
containerRef.current.scrollTo(0, percent * scrollable)
}
}, [percent]);

return (
<div className="lyrics">
<div ref={containerRef} className="lyrics" onWheel={onWheel}>
<div
ref={contentRef}
className="lyrics__content"
dangerouslySetInnerHTML={{ __html: content }}
style={{ transform: `translateY(-${(percent * 110).toFixed(4)}%)` }}
/>
</div>
);
Expand Down
10 changes: 5 additions & 5 deletions src/scss/views/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,18 @@
width: 70%;
height: 100%;
margin-top: 50px;
overflow-y: hidden;
position: relative;
overflow-y: scroll;
scroll-behavior: smooth;

&__content {
font-size: 1.6rem;
line-height: 2.2rem;
position: absolute;
top: 50%;
left: 10%;
width: 80%;
transition: transform 0.9s linear;
margin: 0 auto;
text-align: center;
padding-top: 40vh;
padding-bottom: 40vh;

@include responsive(null, null, $bp_medium) {
font-size: 1.4rem;
Expand Down

0 comments on commit 35e1eb2

Please sign in to comment.