Back
Learn how to build a captivating loader inspired by soap bubbles that burst into delightfully animated fragments, providing a playful experience while your content loads.
In this article, we will explore the creation of a unique loading component that introduces a playful animation using a bubble burst effect. By leveraging accessible, semantic HTML and CSS-only animations, this tutorial provides step-by-step guidance to help beginners craft an engaging UI loader.
The HTML structure for our Bubble Burst Loader is simple yet effective. It features a container to centralize the loader visually, and a button that initiates the loading animation. We use semantic HTML to ensure accessibility and enhance SEO.
<div class="bubble-container">
<button onclick="burstBubbles()" aria-label="Start loading with bubble burst" class="bubble-loader-button">
<span class="loader-text">Loading...</span>
</button>
</div>
<div class="bubble-container"> sets up the central alignment, using flexbox for easy manageability within full-screen height. It's a simple yet effective way to ensure our loader is positioned attractively.<button> element triggers the animation and includes an aria-label to improve accessibility. This attribute helps screen reader users understand the button's function.The JavaScript function burstBubbles() starts the animation cycle. We manipulate the button’s class list to initiate the CSS animation and update the button's text to reflect the loading state.
function burstBubbles() {
let button = document.querySelector('.bubble-loader-button');
let text = document.querySelector('.loader-text');
text.textContent = "Loading...";
button.classList.add('burst-animation');
setTimeout(() => {
text.textContent = "Loaded";
button.classList.remove('burst-animation');
}, 3000);
}
querySelector retrieves our button and text, crucial for toggling states and visual appearance through CSS classes.setTimeout function ensures the animation runs for a designated period (3 seconds), simulating a loading sequence.The CSS styles use Glassmorphism, a modern design trend, to give the loader a sophisticated, soft-focus appearance.
.bubble-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.bubble-loader-button {
border: none;
padding: 15px 30px;
border-radius: 50px;
background: rgba(255,255,255,0.2);
backdrop-filter: blur(10px);
color: #333;
font-size: 18px;
font-weight: bold;
transition: transform 0.3s;
cursor: pointer;
box-shadow: inset 0 0 0 2px #ddd;
}
.bubble-loader-button class utilizes a backdrop-filter to create a Glassmorphism effect, ensuring that the button remains visually intriguing.transition property enables smooth scaling during animations, enhancing user interaction.We also implement an animation loop with the @keyframes rule to offer a captivating burst effect:
.burst-animation {
animation: burst 1s infinite;
}
@keyframes burst {
0% { transform: scale(1); }
50% { transform: scale(1.3); background: rgba(255,255,255,0.5); }
100% { transform: scale(1); }
}
@keyframes burst lets the button appear to inflate and return to its original size, mimicking the delicate popping of bubbles.Ultimately, the Bubble Burst Loader not only fulfills a functional role but also adds a layer of dynamic visual appeal, making the waiting process enjoyable for users.
<div class="bubble-container">
<button onclick="burstBubbles()" aria-label="Start loading with bubble burst" class="bubble-loader-button">
<span class="loader-text">Loading...</span>
</button>
</div>
<script>
function burstBubbles() {
let button = document.querySelector('.bubble-loader-button');
let text = document.querySelector('.loader-text');
text.textContent = "Loading...";
button.classList.add('burst-animation');
setTimeout(() => {
text.textContent = "Loaded";
button.classList.remove('burst-animation');
}, 3000);
}
</script>
<style>
.bubble-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.bubble-loader-button {
border: none;
padding: 15px 30px;
border-radius: 50px;
background: rgba(255,255,255,0.2);
backdrop-filter: blur(10px);
color: #333;
font-size: 18px;
font-weight: bold;
transition: transform 0.3s;
cursor: pointer;
box-shadow: inset 0 0 0 2px #ddd;
}
.bubble-loader-button:focus {
outline: 3px solid #aaa;
}
.burst-animation {
animation: burst 1s infinite;
}
@keyframes burst {
0% { transform: scale(1); }
50% { transform: scale(1.3); background: rgba(255,255,255,0.5); }
100% { transform: scale(1); }
}
</style>
Thank you for reading this article.
Comments