Skip to content

Instantly share code, notes, and snippets.

@lewdev
Created February 6, 2023 10:04
Show Gist options
  • Select an option

  • Save lewdev/0ed3bcc830b2cc3c5c08cdad3c37c34c to your computer and use it in GitHub Desktop.

Select an option

Save lewdev/0ed3bcc830b2cc3c5c08cdad3c37c34c to your computer and use it in GitHub Desktop.
JS/CSS Notify Implementation with Bootstrap 5.
<!doctype html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>
<style>
.notify {
position: fixed;
top: -5rem;
left: 20%;
width: 60%;
font-size: 1.5rem;
display: block;
white-space: normal;
animation: 2s 2 alternate slidein ;
}
@keyframes slidein {
from { top: -5rem; }
50% { top: 5%; }
to { top: 5%; }
}
</style>
<body>
<p id=o></p>
<script>
const notify = (type, message) => {
console.log(type, message);
const elem = document.createElement('div');
elem.className = `notify badge bg-${type}`;
elem.innerHTML = message;
document.body.appendChild(elem);
setTimeout(() => elem.parentNode.removeChild(elem), 5000);
};
let count = 0;
</script>
<button class="btn btn-primary" onclick='notify("success", "Button Press Count " + ++count)'>Notify</button>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment