Skip to content

Commit

Permalink
Don't play video on hover on non-hoverable devices
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Feb 15, 2025
1 parent 82a4866 commit f806e40
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/post/attachments/visual/attachment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ export function VisualAttachment({
const pixRatio = usePixelRatio();

const handleMouseEnter = useEvent((e) => {
e.target.play();
if (window.matchMedia?.('(hover: hover)').matches) {
e.target.play();
}
});
const handleMouseLeave = useEvent((e) => {
e.target.pause();
e.target.currentTime = 0;
if (window.matchMedia?.('(hover: hover)').matches) {
e.target.pause();
e.target.currentTime = 0;
}
});
const [currentTime, setCurrentTime] = useState(0);
const handleTimeUpdate = useEvent((e) => setCurrentTime(Math.floor(e.target.currentTime)));
Expand Down

0 comments on commit f806e40

Please sign in to comment.