Skip to content

Commit

Permalink
Added Preloader
Browse files Browse the repository at this point in the history
  • Loading branch information
AsmitaMishra24 committed Jul 5, 2024
1 parent 8f1f931 commit aefc935
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
8 changes: 4 additions & 4 deletions client/src/components/Preloader/Preloader.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
body{
overflow: hidden;
}

.preloader {
position: fixed;
top: 0;
Expand All @@ -18,6 +14,10 @@ body{
transform: translate3d(0, 0, 0);
}

body.preloader-active {
overflow: hidden;
}

.preloader-animation {
width: 500px;
height: 500px;
Expand Down
41 changes: 25 additions & 16 deletions client/src/components/Preloader/Preloader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ import preloaderAnimation from "./Preloader.json";
import "./Preloader.css";

const Preloader = () => {
const [fadeIn, setFadeIn] = useState(true);
const [loading, setLoading] = useState(true);
const [fadeIn, setFadeIn] = useState(true);
const [loading, setLoading] = useState(true);

useEffect(() => {
const timeout = setTimeout(async () => {
setFadeIn(false);
await new Promise(resolve => setTimeout(resolve, 500));
}, 2500);
useEffect(() => {
const timeout = setTimeout(async () => {
setFadeIn(false);
await new Promise(resolve => setTimeout(resolve, 500));
setLoading(false);
}, 2500);

return () => clearTimeout(timeout);
}, []);
return () => clearTimeout(timeout);
}, []);

if (!loading) return null;
useEffect(() => {
if (loading) {
document.body.classList.add('preloader-active');
} else {
document.body.classList.remove('preloader-active');
}
}, [loading]);

return (
<div className={`preloader ${fadeIn ? "fade-in" : "fade-out"}`}>
<Lottie className="preloader-animation" animationData={preloaderAnimation} />
</div>
);
if (!loading) return null;

return (
<div className={`preloader ${fadeIn ? "fade-in" : "fade-out"}`}>
<Lottie className="preloader-animation" animationData={preloaderAnimation} />
</div>
);
};

export default Preloader;
export default Preloader;

0 comments on commit aefc935

Please sign in to comment.