Back
A detailed guide to creating a modern, dynamic snackbar notification that enhances user experience with smooth animations and aesthetic design.
<div id="snackbar" class="snackbar">This is a snackbar notification</div> <button onclick="showSnackbar()" class="snackbar-button">Show Snackbar</button>
.snackbar {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
transition: visibility 0s, opacity 0.5s linear;
}
.snackbar.show {
visibility: visible;
opacity: 1;
}
.snackbar-button {
background-color: #4caf50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
display: inline-block;
font-size: 16px;
margin: 20px 10px;
cursor: pointer;
border-radius: 8px;
}
function showSnackbar() {
let snackbar = document.getElementById('snackbar');
snackbar.className = 'snackbar show';
setTimeout(function() {
snackbar.className = snackbar.className.replace('show', '');
}, 3000);
}
<div id="snackbar" class="snackbar">This is a snackbar notification</div>
<button onclick="showSnackbar()" class="snackbar-button">Show Snackbar</button>
<script>
function showSnackbar() {
let snackbar = document.getElementById('snackbar');
snackbar.className = 'snackbar show';
setTimeout(function() {
snackbar.className = snackbar.className.replace('show', '');
}, 3000);
}
</script>
<style>
.snackbar {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
transition: visibility 0s, opacity 0.5s linear;
}
.snackbar.show {
visibility: visible;
opacity: 1;
}
.snackbar-button {
background-color: #4caf50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
display: inline-block;
font-size: 16px;
margin: 20px 10px;
cursor: pointer;
border-radius: 8px;
}
</style>
Thank you for reading this article.
Comments
No comments yet. Be the first to comment!