mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 04:49:45 +00:00
смена фона на главной по таймеру
This commit is contained in:
1 parent
4fcb103c01
commit
0c3106ba09
1 file changed
+20
-10
@@ -17,24 +17,34 @@ import Numbers from "@/widgets/Numbers";
|
||||
const MainPage = () => {
|
||||
const { setRef } = useContext(RootContext);
|
||||
const [headerBgUrl, setHeaderBgUrl] = useState("");
|
||||
const [nextBgUrl, setNextBgUrl] = useState("");
|
||||
const [fade, setFade] = useState(false);
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const { data: mediaData, isLoading, isError } = useMedia();
|
||||
|
||||
useEffect(() => {
|
||||
const artMedia = mediaData?.filter((el) => el.category === "art");
|
||||
|
||||
if (artMedia && artMedia.length > 0) {
|
||||
setHeaderBgUrl(artMedia[0].src);
|
||||
}
|
||||
let index = 0;
|
||||
|
||||
const navbar = document.getElementById("navbar");
|
||||
if (navbar) {
|
||||
navbar.classList.add("transparent");
|
||||
}
|
||||
const intervalId = setInterval(() => {
|
||||
const nextIndex = (index + 1) % artMedia.length;
|
||||
const nextImage = artMedia[nextIndex].src;
|
||||
|
||||
return () => {
|
||||
if (navbar) {
|
||||
navbar.classList.remove("transparent");
|
||||
}
|
||||
};
|
||||
setNextBgUrl(nextImage);
|
||||
setFade(true);
|
||||
|
||||
setTimeout(() => {
|
||||
setHeaderBgUrl(nextImage);
|
||||
setFade(false);
|
||||
index = nextIndex;
|
||||
}, 1000);
|
||||
}, 600000); // 10 минут
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}
|
||||
}, [mediaData]);
|
||||
|
||||
if (isLoading) {
|
||||
|
||||
Reference in new issue
Block a user