Merge pull request #939 from jaedb/feat/901-lyrics-manual-scroll
Feat/901 lyrics manual scroll
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import Modal from './Modal';
|
import Modal from './Modal';
|
||||||
import Thumbnail from '../../components/Thumbnail';
|
import Thumbnail from '../../components/Thumbnail';
|
||||||
@ -17,12 +17,24 @@ const LyricsScroller = ({
|
|||||||
content = '',
|
content = '',
|
||||||
percent = 0,
|
percent = 0,
|
||||||
}) => {
|
}) => {
|
||||||
|
const containerRef = useRef(null);
|
||||||
|
const contentRef = useRef(null);
|
||||||
|
const [autoScroll, setAutoScroll] = useState(true);
|
||||||
|
const onWheel = () => setAutoScroll(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (autoScroll) {
|
||||||
|
const height = (contentRef.current?.scrollHeight - containerRef.current?.clientHeight) || 0;
|
||||||
|
containerRef.current.scrollTo(0, percent * height)
|
||||||
|
}
|
||||||
|
}, [percent]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="lyrics">
|
<div ref={containerRef} className="lyrics" onWheel={onWheel}>
|
||||||
<div
|
<div
|
||||||
|
ref={contentRef}
|
||||||
className="lyrics__content"
|
className="lyrics__content"
|
||||||
dangerouslySetInnerHTML={{ __html: content }}
|
dangerouslySetInnerHTML={{ __html: content }}
|
||||||
style={{ transform: `translateY(-${(percent * 110).toFixed(4)}%)` }}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -390,18 +390,18 @@
|
|||||||
width: 70%;
|
width: 70%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
overflow-y: hidden;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
|
overflow-y: scroll;
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
|
||||||
&__content {
|
&__content {
|
||||||
font-size: 1.6rem;
|
font-size: 1.6rem;
|
||||||
line-height: 2.2rem;
|
line-height: 2.2rem;
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 10%;
|
|
||||||
width: 80%;
|
width: 80%;
|
||||||
transition: transform 0.9s linear;
|
margin: 0 auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
padding-top: 40vh;
|
||||||
|
padding-bottom: 40vh;
|
||||||
|
|
||||||
@include responsive(null, null, $bp_medium) {
|
@include responsive(null, null, $bp_medium) {
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user