How would I make these notifications slide and fade away to the right instead of just disappearing? and also how to slide the other open notifications up instead of just jumping up?
HTML
<div class="buttons">
<h1>Notifications</h1>
<button onclick="notifySuccess()">
Success
</button>
<button onclick="notifyError()">
Error
</button>
<button onclick="notifyInfo()">
Info
</button>
</div>
<div id="notification-area">
</div>
CSS
* {
font-family:"Raleway";
}
#notification-area {
position:fixed;
top:0px;
right:10px;
width:250px;
height:100vh;
display:flex;
flex-direction:column;
justify-content:flex-top;
}
#notification-area .notification {
position:relative;
padding:15px 10px;
background:#111;
color:#f5f5f5;
font-family:"Raleway";
font-size:14px;
font-weight:600;
border-radius:5px;
margin:5px 0px;
opacity:0;
left:150px;
animation:showNotification 500ms ease-in-out forwards;
}
@keyframes showNotification {
to {
opacity:1;
left:0px;
}
}
#notification-area .notification.success {
background:#389838;
}
#notification-area .notification.error {
background:orangered;
}
#notification-area .notification.info {
background:#00acee;
}
JS
function notify(type,message){
(()=>{
let n = document.createElement("div");
let id = Math.random().toString(36).substr(2,10);
n.setAttribute("id",id);
n.classList.add("notification",type);
n.innerText = message;
document.getElementById("notification-area").appendChild(n);
setTimeout(()=>{
var notifications = document.getElementById("notification-area").getElementsByClassName("notification");
for(let i=0;i<notifications.length;i++){
if(notifications[i].getAttribute("id") == id){
notifications[i].remove();
break;
}
}
},5000);
})();
}
function notifySuccess(){
notify("success","This is demo success notification message");
}
function notifyError(){
notify("error","This is demo error notification message");
}
function notifyInfo(){
notify("info","This is demo info notification message");
}
https://codepen.io/shane9b3/pen/RwRpePw
I can't figure it out, I assume it has something to do with notifications[i].remove(); part. I tried a few different things last week and couldn't get anything working.
Thanks for the help!!