mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 00:35:07 +01:00
Merge pull request #943 from qtchaos/scroll-volume
Allow users to change volume with scroll wheel
This commit is contained in:
commit
ba4713b130
@ -47,8 +47,22 @@ export function Volume(props: Props) {
|
|||||||
if (dragging) percentage = makePercentage(dragPercentage);
|
if (dragging) percentage = makePercentage(dragPercentage);
|
||||||
const percentageString = makePercentageString(percentage);
|
const percentageString = makePercentageString(percentage);
|
||||||
|
|
||||||
|
const handleWheel = useCallback(
|
||||||
|
(event: React.WheelEvent<HTMLDivElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
let newVolume = volume - event.deltaY / 1000;
|
||||||
|
newVolume = Math.max(0, Math.min(newVolume, 1));
|
||||||
|
setVolume(newVolume);
|
||||||
|
},
|
||||||
|
[volume, setVolume],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={props.className} onMouseEnter={handleMouseEnter}>
|
<div
|
||||||
|
className={props.className}
|
||||||
|
onMouseEnter={handleMouseEnter}
|
||||||
|
onWheel={handleWheel}
|
||||||
|
>
|
||||||
<div className="pointer-events-auto flex cursor-pointer items-center py-0">
|
<div className="pointer-events-auto flex cursor-pointer items-center py-0">
|
||||||
<div className="px-4 text-2xl text-white" onClick={handleClick}>
|
<div className="px-4 text-2xl text-white" onClick={handleClick}>
|
||||||
<Icon icon={percentage > 0 ? Icons.VOLUME : Icons.VOLUME_X} />
|
<Icon icon={percentage > 0 ? Icons.VOLUME : Icons.VOLUME_X} />
|
||||||
|
Loading…
Reference in New Issue
Block a user