css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!--<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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console