mirror of
https://github.com/Radiquum/radiquum.github.io.git
synced 2025-09-03 21:15:36 +05:00
feat: add random timeout before autoplay
Some checks failed
Deploy Next.js site to Pages / build (push) Has been cancelled
Deploy Next.js site to Pages / deploy (push) Has been cancelled
Some checks failed
Deploy Next.js site to Pages / build (push) Has been cancelled
Deploy Next.js site to Pages / deploy (push) Has been cancelled
This commit is contained in:
parent
c9f0b7ab24
commit
3fb066fb1b
1 changed files with 12 additions and 1 deletions
|
@ -23,6 +23,8 @@ export const ProjectLink = ({
|
|||
url,
|
||||
preview,
|
||||
}: ProjectLinkProps) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const [timeoutId, setTimeoutId] = useState<any>(null);
|
||||
const [shouldUseCarousel] = useState(preview ? preview.length > 1 : false);
|
||||
const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true }, [
|
||||
Autoplay({ delay: 5000, playOnInit: false }),
|
||||
|
@ -37,10 +39,19 @@ export const ProjectLink = ({
|
|||
const autoplay = emblaApi?.plugins()?.autoplay;
|
||||
if (!autoplay) return;
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
if (!isInView) {
|
||||
autoplay.stop();
|
||||
} else {
|
||||
autoplay.play();
|
||||
const randTimeout = Math.floor(Math.random() * 2500);
|
||||
setTimeoutId(
|
||||
setTimeout(() => {
|
||||
autoplay.play();
|
||||
}, randTimeout)
|
||||
);
|
||||
}
|
||||
}, [shouldUseCarousel, emblaApi, isInView]);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue