Posted in Notifications
5450
10:57 pm, March 1, 2022

Toast Messages and Notifications Standalone Library no JQuery - notify.js

What is notify.js?

This is a small standalone javascript library that allows you to attach toast type messages that appear in the top right corner of your display with selected messages. 

Preview


a preview of notify.js

What can i use this for?

If you have some messages that you want the user to see, that do not get in the way too much this could be a nice option. The only Issue i found with this is that maybe the messages do not appear long enough and if you miss a message there is no way to get it back.

Conclusion

A great small message library, with 5kb of CSS and 2kb of javascript, it is very lightweight and should not add much loading time to your project. 

Original Source

Thanks to the author sh3mahan for his git repo.

Toast Messages and Notifications Standalone Library no JQuery - notify.js Demo

View Demo Full Screen View Demo New Tab

Toast Messages and Notifications Standalone Library no JQuery - notify.js Code

HTML

<!-- The Buttons to Launch the Toast Messages -->
<button class="btnLaunch1">Info with content</button>
<button class="btnLaunch2">Success with content</button>
<button class="btnLaunch3">Danger with sound</button>
<button class="btnLaunch4">Warning</button>
<!-- The Buttons to Launch the Toast Messages -->

<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>
<p>Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.</p>

CSS

.btnLaunch1, .btnLaunch2, .btnLaunch3, .btnLaunch4 {
  padding: 10px;
  margin: 10px;
  background-color: #fff;
  border: 2px solid #0057fa;
  border-radius: 100px;
}

.btnLaunch1:hover, .btnLaunch2:hover, .btnLaunch3:hover, .btnLaunch4:hover {
  border: 2px solid #002261;
}

/* Notify container */
#notifyContainer {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  width: 100%;
  position: fixed;
  margin: 0 auto;
  padding: 0;
  z-index: 999;
  max-width: 320px;
}

.top_right {
  top: 0;
  left: 50%;
  -webkit-transform: translate(-50%, 0);
          transform: translate(-50%, 0);
  -webkit-box-orient: vertical;
  -webkit-box-direction: reverse;
      -ms-flex-direction: column-reverse;
          flex-direction: column-reverse;
}

.top_left {
  top: 0;
  left: 50%;
  -webkit-transform: translate(-50%, 0);
          transform: translate(-50%, 0);
  -webkit-box-orient: vertical;
  -webkit-box-direction: reverse;
      -ms-flex-direction: column-reverse;
          flex-direction: column-reverse;
}

.bottom_right {
  top: 0;
  left: 50%;
  -webkit-transform: translate(-50%, 0);
          transform: translate(-50%, 0);
  -webkit-box-orient: vertical;
  -webkit-box-direction: reverse;
      -ms-flex-direction: column-reverse;
          flex-direction: column-reverse;
}

.bottom_left {
  top: 0;
  left: 50%;
  -webkit-transform: translate(-50%, 0);
          transform: translate(-50%, 0);
  -webkit-box-orient: vertical;
  -webkit-box-direction: reverse;
      -ms-flex-direction: column-reverse;
          flex-direction: column-reverse;
}

/* Notify */
.alerts {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: start;
      -ms-flex-align: start;
          align-items: flex-start;
  margin: 10px 0 0 0;
  padding: 0 10px;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  font-family: sans-serif;
  width: 100%;
  border-radius: 4px;
  -webkit-box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
          box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
  font-size: 12.5px;
  -webkit-transition: all 0.3 ease-out;
  transition: all 0.3 ease-out;
}

.alerts {
  -webkit-animation: fadeIn .3s ease-in 0s 1 forwards;
          animation: fadeIn .3s ease-in 0s 1 forwards;
}

.alerts-success {
  background-color: rgba(209, 231, 221, 0.96);
  color: #0f5132;
}

.alerts-danger {
  background-color: rgba(248, 215, 218, 0.96);
  color: #842029;
}

.alerts-warning {
  background-color: rgba(255, 243, 205, 0.96);
  color: #664d03;
}

.alerts-info {
  background-color: rgba(207, 244, 252, 0.96);
  color: #055160;
}

.alerts > h3 {
  width: 100%;
  display: inline-block;
  font-size: 12.5px;
  margin: 0;
  padding: 10px 0;
  line-height: 1.5;
}

.alerts > p {
  width: 100%;
  min-height: 0px;
  display: inline-block;
  font-size: 12.5px;
  padding: 0 0 10px;
  margin: 0;
}

.fadeOut {
  -webkit-animation: fadeOut .3s ease-out 0s 1 forwards;
          animation: fadeOut .3s ease-out 0s 1 forwards;
}

@-webkit-keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@-webkit-keyframes fadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes fadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

button:active, button:focus {
  outline: none;
}

button::-moz-focus-inner {
  border: 0;
}

@media (min-width: 769px) {
  .top_right {
    top: 0;
    bottom: auto;
    right: 10px;
    left: auto;
    -webkit-transform: none;
            transform: none;
    -webkit-box-orient: vertical;
    -webkit-box-direction: reverse;
        -ms-flex-direction: column-reverse;
            flex-direction: column-reverse;
  }
  .top_left {
    top: 0;
    bottom: auto;
    right: auto;
    left: 10px;
    -webkit-transform: none;
            transform: none;
    -webkit-box-orient: vertical;
    -webkit-box-direction: reverse;
        -ms-flex-direction: column-reverse;
            flex-direction: column-reverse;
  }
  .bottom_right {
    top: auto;
    bottom: 0;
    right: 10px;
    left: auto;
    -webkit-transform: none;
            transform: none;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
        -ms-flex-direction: column;
            flex-direction: column;
  }
  .bottom_left {
    top: auto;
    bottom: 0;
    right: auto;
    left: 10px;
    -webkit-transform: none;
            transform: none;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
        -ms-flex-direction: column;
            flex-direction: column;
  }
}

Javascript

/* notify.js */
document.body.click()
// const Notify = (o)=> {
function Notify(o) {
	// default params
	if (!o) o = {}
	if (!o.corner) o.corner = "top_right";
	if (!o.delay) o.delay = 5000;
	if (!o.maxElem) o.maxElem = 10;
	
	const notifyContainer = document.createElement("div");
				notifyContainer.id = "notifyContainer";
				notifyContainer.className = o.corner;
	document.body.appendChild(notifyContainer);

	const countAlerts = document.getElementsByClassName("alerts");

	this.notifyCreate = (style, head, content, sound) => {
		let alerts = document.createElement("div");
				alerts.className = "alerts";
				alerts.className += " alerts-" + style;
		if (!content) {
			alerts.innerHTML = `<h3>${head}</h3>`;
		} else {
			alerts.innerHTML = `<h3>${head}</h3><p>${content}</p>`;
		};
				notifyContainer.appendChild(alerts);
		if (sound) {
			const audio = new Audio('../assets/sound/notification.mp3');
					audio.play();
		}
		setTimeout(function () {
			alerts.classList.toggle("fadeOut");
		}, o.delay - 300);
		setTimeout(function () {
			notifyContainer.removeChild(alerts);
		}, o.delay);
	};

	this.render = (r) => {
		// default params
		if (!r) r = {}
		const exceptionsParam = !r.style || ( r.style != 'info' && r.style != 'success' && r.style != 'danger' && r.style != 'warning'); 
		// console.log(`${exceptionsParam} = ${!r.style} || ( ${r.style != 'info'} && ${r.style != 'success'} && ${r.style != 'danger'} && ${r.style != 'warning'})`)
		r.style = exceptionsParam ? 'info' : r.style;
		r.sound = !r.sound ? false : true;
		if (!r.head) {
			r.head = 'Hi, I\'m Notify Native — JS Library';
			r.content = ''
		} else {
			r.head = r.head;
			r.content = r.content;
		};
		// r.head = !r.head ? '' : r.head;
		// r.content = !r.content ? '' : r.content;
		
		
		
		if (countAlerts.length < o.maxElem) {
			this.notifyCreate(r.style, r.head, r.content, r.sound);
		};
	};
};
/* notify.js */

/* Add + Setup the alerts */
	// initialization
	// const notify = new Notify({
	// 	corner: "top_right", // Select the angle of appearance of notifications, e.g. "top_left" or "bottom_right" (default: top_right)
	// 	delay: 5000, // Set the delay in milliseconds (default: 5000)
	// 	maxElem: 12 // Set the maximum number of notifications on the screen (default: 10)
	// });
	
	const notify = new Notify();
	// adding handlers to buttons and notification rendering
const noty_1 = document.querySelector(".btnLaunch1");
noty_1.addEventListener("click", () => {
	notify.render({
		head: "Info",
		content: "A simple info alert—check it out!"
	});
});
const noty_2 = document.querySelector(".btnLaunch2");
noty_2.addEventListener("click", () => {
	notify.render({
		style: "success",
		head: "Success",
		content: "A simple success alert—check it out!"
	});
});
const noty_3 = document.querySelector(".btnLaunch3");
noty_3.addEventListener("click", () => {
	notify.render({
		style: "danger",
		head: "Danger",
		content: "A simple warning alert—check it out!",
		sound: true
	});
});
const noty_4 = document.querySelector(".btnLaunch4");
noty_4.addEventListener("click", () => {
	notify.render({style: "warning"});
});
// 	setTimeout(() => {
// 		document.querySelector('#notifyContainer').click();
// 	}, 100);
// 	document.querySelector('#notifyContainer').addEventListener('click', function() {
//   setTimeout(() => {
// 		notify.render({
// 			style: "asdavsdf",
// 			// head: "Hello!",
// 			content: "A simple success alert—check it out!"
// 		});
// 	}, 1000);
// });
/* Add the alerts */

External Link for Toast Messages and Notifications Standalone Library no JQuery - notify.js

No Items Found.

Add Comment
Type in a Nick Name here
 
Related Search Terms
Search Code
Search Code by entering your search text above.
Welcome to CSSBundle.com

Hi there and welcome to CSSBundle. Here at CSS Bundle we aim to find the best css and javascript bundles and demos and add them here to make them easy to find all in one place.

If you would like to stay up to date with our latest updates you can subscribe to our mailing list where we will send you one email per week with the latest updates, no spam emails just the latest updates.

Random Quote


Latest Code
html Video different sources on screen sizes video embed html responsive css animations Animated Triangles on Canvas JS HTML HTML Canvas Instant colour fill with HTML Canvas javascript Transform Text into Images using SnapText JS CSS Tools Fancy Border Radius CSS Generator Tool - spin animation keyframes CSS Tools CSS Drop Filter Shadow Creator CSS Slider A CSS and HTML Only Carousel Slider CSS Z-Index Z-Index Code Front - CSS to change z-index when element is active sections section with image to the right text to the left gradient Sections Two Clickable Logo Promo Box Section Foundation HTML CSS Sections Inline Contact Form Formatting HTML CSS Sections Overview full width section in Poppins font with light gray background using foundation Interactive Images Map Image with Easy Dots and Titles using only CSS HTML Sections Social Header Links easy Drop in Code with Font Awesome Icons Sections Responsive Friendly Subscribe to our Newsletter Section CSS Tips Create a button with CSS, HTML and Center it! CSS Text Formatting Truncate Text to an amount of lines using line-clamp CSS Positions Item Positioning in CSS CSS Tips Draw a Circle in CSS css animations Magical Text Effect Bootstrap 4.2 Kitchen Sink CSS Frameworks Make your site look like windows 7 CSS Backgrounds Fancy up your banner image hero sections using overlay gradients CSS Modal Floating Modal Message Fixed on the Bottom of the Screen CSS Modal Create a modal with only CSS css grid display items in a css grid CSS Text Effects Using the selection selector to change the default highlight color Text Truncate your Text with CSS CSS Cursors Change your cursor into an Emoji Cursor or Image Cursor CSS How to Center Everything or Anything with CSS CSS Animations Smooth Scrolling with just CSS CSS Animations Radial Glow under cursor on box hover over effect CSS Shadows Using a filter drop shadow for transparent images CSS Animations Pure CSS 3D Flipping Book with Animations CSS Create a checkerboard background pattern with CSS CSS Animations button animations hover and fill animation CSS Animations button on focus swing animation CSS Animations Animated Button Border when Active Quick CSS create a border with top triangle in css CSS Animations Single Element CSS Spinners CSS Animations CSS Shake - Shake up your elements CSS Framework NES-style(8bit-like) CSS Framework CSS Tips Why to use a CSS Reset? Web Developer Checklists Front-End Checklist Icons Font Awesome Icons CSS Animation Animate Stuff with Animate.css CSS Animations Check Wave Click a Checkbox and Watch the Animation Animation Cloudy spiral animation with CSS3 Notifications Toast Messages and Notifications Standalone Library no JQuery - notify.js Image Zoom Silky Smooth Image Zoom and Lightbox