cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!--<div class="notification">
  <div class="logo">
  	<img src=""/>
  </div>
  <h3 class="notification-message">You've a lot of work unsaved. Make Sure you save it</h3>
  <button class="btn-close">x</button>
</div>-->

<main>
  <button class="btn-notifier gen" data-not-msg="Todd Moddo wanna work with you!">general</button>
  
<button class="btn-notifier success" data-not-msg="Your request has been merged!">success</button>
  
  <button class="btn-notifier error" data-not-msg="Oops! We couldn't fetch your data">error</button>
  
    <button class="btn-notifier warning" data-not-msg="Your battery level is very low, make sure you save your pen.">warning</button>
  
  </main>
            
          
!
            
              body {
  background-color: #ffffff;
  color: #555;
  font-size: 1.1em;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  margin: 0;
}

button {
  border: 0;
  outline: 0;
  cursor: pointer;
}

.notification {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: .5em 1em;
  background: #456;
  font-size: 1.4rem;
  color: white;
  box-shadow: 0 .05em .1em rgba(51, 51, 51, 0.16);
  transition: all .1s ease-out;
  pointer-events: none;
  z-index: 100;
  transform: translateY(-105%);
}

.notification .logo {
	flex: 0 0 2em;
  height: 2em;
  border-radius: 50%;
  background: white;
}

.notification .logo img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.notification .notification-message {
	flex: 1;
  margin: 0 1em;
  font-size: 0.9em;
}

.notification .btn-close {
	border: 0;
  outline: 0;
  flex: 0 0 2em;
  height: 2em;
  background: #456;
  color: white;
  line-height: 0.5em;
  margin-left: auto;
  border-radius: 50%;
  cursor: pointer;
}

.notification .btn-close:active {
  transform: scale(0.9);
}


.notification.is-open {
  position: static;
  transform: translate(0);
  pointer-events: auto;
}

.notification.success {
  background: #5bc467;
}

.notification.error {
  background: #f86016;
}

.notification.gen {
  background: #26b5c1;
}

.notification.warning {
  background: #f8cd16;
}




/*** Extra Stuff ***/

main {
  margin: 3em 0;
  text-align: center;
  transition: .1s;
}

main .btn-notifier {
	text-transform: uppercase;
  padding: 1rem 5rem;
  background: #814de9 padding-box;
  color: white;
  margin-bottom: 1rem;
  cursor: pointer;
  box-shadow: 0 .3em .2em -.2em rgba(51, 51, 51, 0.53);
}

.btn-notifier:active {
  box-shadow: inset 0 .15em 1em rgba(51, 51, 51, 0.4);
}


@media screen and (max-width: 480px) {
    html {
    font-size: 13px
  }
}
@media screen and (max-width: 300px) {

  .notification .notification-message {
  	margin: 1em 0;
    order: 3;
    flex: 1 1 100%;
  }
}
            
          
!
            
              var notifier= (function() {
  
  
  function createAndAppendNotification() {
    //create necessary elements
    var notification= document.createElement("div"),
        logo= document.createElement("logo"),
        logoImg= document.createElement("img"),
        notificationMsg= document.createElement("h3"),
        btnClose= document.createElement("button");
    
   //add classes
    notification.classList.add("notification");
    notification.classList.add("gen");
logo.classList.add("logo");
notificationMsg.classList.add("notification-message");
btnClose.classList.add("btn-close");
    
    btnClose.textContent= "x";
    
//append elements
    
    logo.appendChild(logoImg);
    notification.appendChild(logo);
    notification.appendChild(notificationMsg);
    notification.appendChild(btnClose);
    document.body.insertBefore(notification, document.body.children[0]);
    
    return {
      notification: notification,
      logo: logoImg,
      msg: notificationMsg,
      btnClose: btnClose
    }
  }

  var elements= createAndAppendNotification(),
           not= elements.notification,
    stateClass= "gen";
  
  
 function setNotification(logoSrc, msg) {
   elements.logo.setAttribute("src", logoSrc);
   elements.msg.textContent= msg;
 }
  
  
  function showNotification(state) {

 if(stateClass) { 
       not.classList.remove(stateClass);
              }
    
    
    switch(state) {
      case "success":
        not.classList.add("success"); 
        break;
        
         case "error":
        not.classList.add("error"); 
        break;
        
         case "gen":
        not.classList.add("gen"); 
        break;
        
         case "warning":
        not.classList.add("warning"); 
        break;
    }
    
     not.classList.add("is-open");
  }
  
  
     var trans= getComputedStyle(not).getPropertyValue("transition-duration"),
    stateClass= "gen";
  
          const delay= Number( trans.substring(0, trans.length-1));
  
    function closeNotification() {
  not.classList.remove("is-open");
     
     setTimeout(()=> {
 not.classList.remove(stateClass);
           }, delay*1000);
        
  }
  
  elements.btnClose.addEventListener("click", closeNotification, false);   
  
  window.addEventListener("keydown", function(e) {
    if(e.keyCode == 27 && not.classList.contains("is-open")) {
      closeNotification();
    }
  });
  
  return {
    notify: function(state, options) {
      
      if(typeof options=== "object") {
    setNotification(options.logo || "", options.msg);
      } else {
        throw new Error("Second arguments should be an object having keys as 'options' (e.g.- logo)");
      }
      
      if(typeof state=="string") {
      notFirstTime= state;
      showNotification(state);
      stateClass= state;
      } else {
        throw new Error("First argument should be a string representing state of notificaion");
      }
      
    }
  }
})();



(function() {
  //helper function
function $$(selector, context) {
    context = context || document;
    var elements = context.querySelectorAll(selector);
    return Array.prototype.slice.call(elements);
} 
  
  $$(".btn-notifier").forEach((button)=> {
    button.addEventListener("click", function() {
      
    var state= this.classList[1],
        msg= this.getAttribute("data-not-msg");
      notifier.notify(state, {logo: "https://tympanus.net/Tutorials/AnimatedAnimals/img/link-fox.png", msg: msg});
         });
  });
})();

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console