Skip to content

Commit cd1491a

Browse files
committed
Added preloader animation
1 parent 0701473 commit cd1491a

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

index.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,56 @@
2727
/>
2828
</head>
2929
<body>
30+
<style>
31+
/* Preloader overlay */
32+
#preloader {
33+
position: fixed;
34+
inset: 0;
35+
display: grid;
36+
place-items: center;
37+
background: #ffffff;
38+
z-index: 9999;
39+
transition: opacity 300ms ease;
40+
}
41+
#preloader.hidden {
42+
opacity: 0;
43+
pointer-events: none;
44+
}
45+
46+
/* CSS Loader (provided) */
47+
/* HTML: <div class="loader"></div> */
48+
.loader {
49+
width: calc(6 * 30px);
50+
height: 50px;
51+
display: flex;
52+
color: #8d7958;
53+
filter: drop-shadow(30px 25px 0 currentColor) drop-shadow(60px 0 0 currentColor) drop-shadow(120px 0 0 currentColor);
54+
clip-path: inset(0 100% 0 0);
55+
animation: l12 2s infinite steps(7);
56+
}
57+
.loader:before {
58+
content: "";
59+
width: 30px;
60+
height: 25px;
61+
--c: no-repeat radial-gradient(farthest-side, currentColor 92%, #0000);
62+
background:
63+
var(--c) left / 70% 70%,
64+
var(--c) right / 20% 20%,
65+
var(--c) top 0 right 15% / 20% 20%,
66+
var(--c) bottom 0 right 15% / 20% 20%;
67+
}
68+
@keyframes l12 {
69+
100% {
70+
clip-path: inset(0 -30px 0 0);
71+
}
72+
}
73+
</style>
74+
75+
<!-- Preloader overlay with CSS loader -->
76+
<div id="preloader" role="status" aria-label="Loading">
77+
<div class="loader"></div>
78+
</div>
79+
3080
<div id="root"></div>
3181
<script type="module" src="/src/main.tsx"></script>
3282
</body>

src/components/Projects.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { trackProjectClick } from "../analytics";
33
import { Swiper, SwiperSlide } from "swiper/react";
44
import type { Swiper as SwiperType } from "swiper";
5-
import { Navigation, Pagination, Keyboard, A11y, Autoplay } from "swiper/modules";
5+
import { Navigation, Pagination, Keyboard } from "swiper/modules";
66
import "swiper/css";
77
import "swiper/css/navigation";
88
import "swiper/css/pagination";
@@ -206,14 +206,13 @@ export default function Projects() {
206206
</div>
207207

208208
<Swiper
209-
modules={[Navigation, Pagination, Keyboard, A11y, Autoplay]}
209+
modules={[Navigation, Pagination, Keyboard]}
210210
spaceBetween={28}
211211
slidesPerView={1}
212212
slidesOffsetBefore={40}
213213
navigation
214214
pagination={{ clickable: true, dynamicBullets: true }}
215-
keyboard={{ enabled: true }}
216-
autoplay={{ delay: 5000, disableOnInteraction: true, pauseOnMouseEnter: true }}
215+
keyboard={{ enabled: true, onlyInViewport: true, pageUpDown: false }}
217216
onInit={(swiper: SwiperType) => {
218217
swiper.el.classList.toggle("fade-left", !swiper.isBeginning);
219218
swiper.el.classList.toggle("fade-right", !swiper.isEnd);

src/main.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,16 @@ createRoot(document.getElementById("root")!).render(
88
<App />
99
</StrictMode>,
1010
);
11+
12+
// Fade out and remove CSS preloader when the page finishes loading
13+
const hidePreloader = () => {
14+
const el = document.getElementById("preloader");
15+
if (!el) return;
16+
el.classList.add("hidden");
17+
window.setTimeout(() => {
18+
el.parentElement && el.parentElement.removeChild(el);
19+
}, 350);
20+
};
21+
22+
// Show the preloader for a fixed 2 seconds
23+
window.setTimeout(hidePreloader, 2000);

0 commit comments

Comments
 (0)