rj-notification displays little information bar. It is highly configurable and great especially for cookies info. This plugin has been created for one of my commercial projects.
- Upload CSS and JS files to your project
- Add proper links to files in your HTML
- Add notification bar with configuration object in your HTML in a way presented in "Configuration" below
To add notification bar with complete configuration object use this code:
const notificationBarName = new RjNotification({
notificationId: 'cookies-info',
notificationBg: '#ffffff',
notificationPosition: 'fixed',
notificationFixedTop: true,
notificationParentId: 'cookies-container',
notificationText: 'This website uses cookies',
notificationExpiryDays: 365,
notificationAnimation: 'disappear',
textColor: '#2a2a2a',
textSize: '12px',
linkActivated: true,
linkAddress: '/terms-of-use',
linkText: 'Learn more',
linkColor: '#6c72ed',
closeBtnText: 'Okay',
closeBtnBgColor: '#6bb600',
closeBtnColor: '#fff',
closeBtnBorder: '1px solid #6bb600',
closeBtnBorderRadius: '5px'
});
The code presented above contains a configuration object. These are also default options so if you don't provide any of options when adding notification bar, notification bar will be added to your page with these options. Now lets get further information about every configuration options:
notificationId
- sets id for your notification bar (string)notificationBg
- sets background color for your notification bar. Supported formats:rgb(123, 123, 123)
,rgba(123, 123, 123, .4)
,#123123
,yellow
(string)notificationPosition
- sets CSSposition
rule of your bar. Choose between:absolute
,relative
,static
andfixed
(string)notificationFixedTop
- ifnotificationPosition
is set tofixed
, you can choose where notification bar should be fixed - to bottom or to top of viewport. IfnotificationPosition
is notfixed
thennotificationFixedTop
changes nothing. Choose between:true
- for fixed to top andfalse
- for fixed to bottom (boolean)notificationParentId
- essential option. Provide id of parent element for your notification bar. For example if you have<footer id="footer-info">
and you providenotificationParentId: 'footer-info'
then notification bar will be added as last child of this element (string)notificationText
- sets main text content of notification bar (string)notificationExpiryDays
- sets number of days after which notification will be displayed again after closing it (cookie expiry days) (number)notificationAnimation
- sets the animation type when closing notification bar. Choose between:disappear
andfall
(string)textColor
- sets main text content color. Supported formats:rgb(123, 123, 123)
,rgba(123, 123, 123, .4)
,#123123
,yellow
(string)textSize
- sets main text content size. Supported every CSSfont-size
formats (string)linkActivated
- if set totrue
then on notification bar there will be a link for - for example "Terms of use". Choose betweentrue
andfalse
(boolean)linkAddress
- iflinkActivated
is set totrue
then it sets the address for link (URL). IflinkActivated
is set tofalse
thenlinkAddress
changes nothing (string)linkText
- iflinkActivated
is set totrue
then it sets the text content for link (URL), for example "Read more". IflinkActivated
is set tofalse
thenlinkText
changes nothing (string)linkColor
- iflinkActivated
is set totrue
then it sets the text content color for link (URL). IflinkActivated
is set tofalse
thenlinkColor
changes nothing (string)closeBtnText
- sets the notification close button's text content, for example 'I understand' (string)closeBtnBgColor
- sets the notification close button's background color. Supported formats:rgb(123, 123, 123)
,rgba(123, 123, 123, .4)
,#123123
,yellow
(string)closeBtnColor
- sets the notification close button's text content color. Supported formats:rgb(123, 123, 123)
,rgba(123, 123, 123, .4)
,#123123
,yellow
(string)closeBtnBorder
- sets the notification close button's border - value should be the same as in CSSborder
rule. e.gborder: 1px solid #000
(string)closeBtnBorderRadius
- sets the notification close button's border radius - value should be the same as in CSSborder-radius
rule. (string)
- JavaScript (ES6)
- CSS
- HTML
Finished