Back
Design an interactive piece-spinner loader that visually assimilates a puzzle solving itself during the loading process.
<div class="puzzle-loader-container">
<div class="puzzle-loader" aria-label="Puzzle Piece Loader" tabindex="0">
<div class="puzzle-piece"></div>
<div class="puzzle-piece"></div>
<div class="puzzle-piece"></div>
<div class="puzzle-piece"></div>
</div>
</div>
const enableReduction = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (!enableReduction) {
let pieces = document.querySelectorAll('.puzzle-piece');
pieces.forEach((piece, index) => {
piece.style.animationDelay = `${index * 0.2}s`;
piece.style.animationDuration = '1.5s';
});
}
.puzzle-loader-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.puzzle-loader {
display: grid;
grid-template-columns: repeat(2, 50px);
grid-template-rows: repeat(2, 50px);
gap: 10px;
transform: rotate(0deg);
animation: spin 2s linear infinite;
}
.puzzle-piece {
width: 50px;
height: 50px;
background: rgba(173, 216, 230, 0.8);
display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
animation: wobble 1.5s ease-in-out infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
@keyframes wobble {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-5px); }
50% { transform: translateX(5px); }
75% { transform: translateX(-5px); }
}
.puzzle-loader:focus-visible, .puzzle-piece:focus-visible {
outline: 3px solid #ffbb00;
outline-offset: 2px;
}
The loader components ensure accessibility, visual flair, and interactivity within contemporary web applications.
<div class="puzzle-loader-container">
<div class="puzzle-loader" aria-label="Puzzle Piece Loader" tabindex="0">
<div class="puzzle-piece"></div>
<div class="puzzle-piece"></div>
<div class="puzzle-piece"></div>
<div class="puzzle-piece"></div>
</div>
</div>
<script>
const enableReduction = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (!enableReduction) {
let pieces = document.querySelectorAll('.puzzle-piece');
pieces.forEach((piece, index) => {
piece.style.animationDelay = `${index * 0.2}s`;
piece.style.animationDuration = '1.5s';
});
}
</script>
<style>
.puzzle-loader-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.puzzle-loader {
display: grid;
grid-template-columns: repeat(2, 50px);
grid-template-rows: repeat(2, 50px);
gap: 10px;
transform: rotate(0deg);
animation: spin 2s linear infinite;
}
.puzzle-piece {
width: 50px;
height: 50px;
background: rgba(173, 216, 230, 0.8);
display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
animation: wobble 1.5s ease-in-out infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
@keyframes wobble {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-5px); }
50% { transform: translateX(5px); }
75% { transform: translateX(-5px); }
}
.puzzle-loader:focus-visible, .puzzle-piece:focus-visible {
outline: 3px solid #ffbb00;
outline-offset: 2px;
}
</style>
Thank you for reading this article.
Comments
No comments yet. Be the first to comment!