Last active
August 26, 2021 12:45
-
-
Save AndryWJ/56a68699b0f9e5a1631b53cc529e6b6b to your computer and use it in GitHub Desktop.
First show messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#snackbar { | |
min-width: 250px; | |
transform: translateX(-50%); | |
background-color: #333; | |
color: #fff; | |
text-align: center; | |
border-radius: 2px; | |
padding: 16px; | |
position: fixed; | |
z-index: 9999999999999; | |
left: 50%; | |
bottom: 30px; | |
animation-fill-mode: forwards; | |
animation-duration: 0.5s; | |
} | |
.snackbar-progressbar{ | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 4px; | |
width: 0%; | |
background-color: red; | |
} | |
@keyframes fadein { | |
from {bottom: 0; opacity: 0; visibility:hidden;} | |
to {bottom: 30px; opacity: 1; visibility:visible;} | |
} | |
@keyframes fadeout { | |
from {bottom: 30px; opacity: 1; visibility:visible;} | |
to {bottom: 0; opacity: 0; visibility:hidden;} | |
} | |
@keyframes move { from { width:0%; } to { width:100%; } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function snackbar(text,time = 6000) { | |
if(window.timer_snackbar != undefined){ clearTimeout(window.timer_snackbar); } | |
var x = document.getElementById("snackbar"); | |
var html = '<div class="snackbar-progressbar"></div><div class="snackbar-content">'+text+'</div>'; | |
if(x == null){ | |
var x = document.createElement("div"); | |
x.id = 'snackbar'; | |
x.innerHTML = html; | |
document.body.append(x); | |
}else{ x.innerHTML = html; } | |
// Відобразити повідомлення | |
x.style.animationName = 'fadein'; | |
// Запустимо прогресбар | |
var animEL = x.querySelector('.snackbar-progressbar'); | |
animEL.style.animation = 'move '+time+'ms linear'; | |
// Закриємо повідомлення | |
window.timer_snackbar = setTimeout(function(){ | |
x.style.animationName = 'fadeout'; | |
}, time); | |
} | |
snackbar('Привіт світ!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment