Simple Notifications Solution
A simple solution for notifications.
It provides a simple notifications system with two kinds of possible behavior.
Some notifications should close themselves without any action from the user.
Some require clicking on the close button.
All closed notifications should be removed from the DOM. The notifications may be on the page when it loads or may be added at any other moment.
It does not use any JavaScript library. The demo uses BULMA css framework.
Demo
You can find the demo here.
How?
The script uses the animationstart
listener for the dynamically added notifications.
Installation
The dist
folder contains the ready for production minified files: Notifications.js
and Notifications.css
... Self-closing notification This one needs user's action. Close <!-- Bottom of body -->
You can also use the cdn solution
... Self-closing notification This one needs user's action. Close <!-- Bottom of body -->
npm:
npm install simple-notifications-solution
Usage:
The recommended markups for a notification are like that:
<!-- self closing notification -->Self-closing notification<!-- or -->Self-closing notification<!-- notification with close button --> This one needs user's action. Close<!-- or --> This one needs user's action. Close
You have to use the notification
class since it's used in the .css file.
You need to add the data-close="self"
attribute to your notification if you want it to close automatically.
To activate the notifications add the following:
var notifications = ;notifications;
You can check it on Codepen here.
Customization
You can initiate Notifications with some options, the available options are:
// the animation-name for the 'in' animation - you will need to modify the .notification in your css accordingly animationInName: 'slidein' // the animation-name for the self-closing notifications - you will have to add the @keyframes declaration in your css animationOutSelf: 'slideout 1s' // the animation-name for animation used to remove the notification on click - you will have to add the @keyframes declaration in your css animationOutClose: 'fadeout 1s' // the selector for the closing element closeButtonSelector: '.delete' // whether you can also close the self-closing notification by clicking on it closeSelfOnClick: true // the vertical distance from the top of the viewport startTopPosition: 8 // the vertical gap between the notifications as they appear on the screen gap: 8 // the waiting time before removing a notification, i - is the number of notifications before the current one 3 + 2*i // the transition used when a notification moves up topTransition: 'top .75s ease-in-out'
Example:
A Codepen demo is available here.
A Codepen demo is available here.