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.

            
              <main id="main">
  <button class="btn-notifier" data-not-state="gen" data-not-msg="You can change your theme anytime." data-not-btn-text="Change Theme" data-not-btn-action="changeTheme">Change Your Theme</button>
   <button class="btn-notifier" data-not-state="warning" data-not-msg="Do you want to remove the triangles?." data-not-btn-text="Yes, Remove 'em " data-not-btn-action="removeTriangles">Remove Triangles</button>
  
  </main>

<div class="triang-con" id="triangCon">
<svg class="triang triang-1" viewBox="0 0 300 300">
  <path d="M0,0 L300,250 0,200"/>
</svg>
  
  <svg class="triang triang-2" viewBox="0 0 300 300">
  <path d="M0,10 L300,0 300,200 0,10"/>
</svg>
  
<svg class="triang triang-3" viewBox="0 0 300 300">
  <path d="M0,100 L300,0 300,200 0,100"/>
</svg>
  
</div>
            
          
!
            
              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 {
	order: 3;
	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 .btn-container {
	order: 1;
  flex: 0 1 auto;
}

.notification .btn-container .btn-action {
	display: inline-block;
	border-radius: .2em;
  padding: 1em 2em;
  margin: 0 1em;
  background: white;
}

.notification .btn-container .btn-action:active {
  opacity: 0.9;
  background: #f8f3f3;
}

.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 {
	position: relative;
  margin: 3em 0;
  text-align: center;
  transition: .1s;
  z-index: 2;
}

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);
}

main .btn-notifier:nth-child(2) {
  display: none;
  opacity: 0;
}

 main.stage-2 .btn-notifier:nth-child(2) {
  display: inline-block;
  opacity: 1;
  transition: all .3s;
}

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

.triang-con {
	position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  pointer-events: none;
}

.triang-con .triang {
	position: absolute;
  width: 20vw;
  opacity: 0.7;
  transition: all .3s ease-out;
}

.triang:nth-child(1) {
	top: 30%;
  fill: #456;
  transform: translateX(-100%);
}

.triang:nth-child(2) {
	top: 20%;
  right: 0;
  fill: #eecb36;
}

.triang:nth-child(3) {
	top: 50%;
	right: 0;
  fill: #3a94ee;
}

.triang:nth-child(2),
.triang:nth-child(3){
  transform: translateX(100%);
}

.dark {
  background: #333;
}

.dark .triang-con.opened .triang {
  transform: translate(0);
}
@media screen and (max-width: 800px) {
    html {
    font-size: 13px;
  }
  
  .notification .btn-close {
    order: 2;
  }
  .notification .btn-container {
  	flex: 0 0 100%;
    order: 3;
    margin: .5em 0;
  }
}


@media screen and (max-width: 300px) {

  .notification .notification-message {
  	margin: 1em 0;
    order: 3;
    flex: 1 1 100%;
  }
}
            
          
!
            
              /***Notifier.js****/

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"),
          btnContainer= document.createElement("section");
           
    
   //add classes
    notification.classList.add("notification");
    notification.classList.add("gen");
logo.classList.add("logo");
notificationMsg.classList.add("notification-message");
btnClose.classList.add("btn-close");
btnContainer.classList.add("btn-container");
    
    btnClose.textContent= "x";
    
//append elements
    
    logo.appendChild(logoImg);
    notification.appendChild(logo);
    notification.appendChild(notificationMsg);
    notification.appendChild(btnClose);
    notification.appendChild(btnContainer);
    document.body.insertBefore(notification, document.body.children[0]);
    
    return {
      notification: notification,
      logo: logoImg,
      msg: notificationMsg,
      btnClose: btnClose,
      btnContainer: btnContainer
    }
  }

  var elements= createAndAppendNotification(),
           not= elements.notification,
    stateClass= "gen";
  
  
  
  
 function setNotification(options) {
   elements.logo.setAttribute("src", options.logo || "");
   elements.msg.textContent= options.msg;
   
   function removeActionButtons() {
    var buttons= elements.btnContainer.children;
    for (var i=0; i< buttons.length; i++) {
      buttons[0].remove();
    }
  }
  
  
     if(elements.btnContainer.children[0]) {
      removeActionButtons();
    }
   
  function addActionButtons(options) {
        var actBtnLength= options.actions.length;
      
 for(var i=0; i < actBtnLength; i++) {
   if(typeof options.actions[i] === "object") {
            let btn= document.createElement("button");
            btn.classList.add("btn-action");
            btn.textContent= options.actions[i].title;
    var idx= i;  btn.addEventListener("click", function() {
    closeNotification();
  options.actions[idx].action();
            });
                         
            elements.btnContainer.appendChild(btn);
   } else {
              throw new Error("notify's second argument's third key should contain an array of only objects");
            }
        }
}
   
   //if options.actions is available
   if(options.actions) {
   
   //if options.actions is an array
     if(Object.getPrototypeOf(options.actions) === Array.prototype) {
       addActionButtons(options);
 } else { 
    throw new Error("notifiy's second argument's third key should contain an array");
 }
   }
 }
  
  
  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(()=> {
     if(!(not.classList.contains("is-open"))) {
 not.classList.remove(stateClass);
     }
           }, (delay*1000) || 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);
      } else {
        throw new Error("Second arguments should be an object having keys as 'options' (e.g.- logo)");
      }
      
      if(typeof state=="string") {
      showNotification(state);
      stateClass= state;
      } else {
        throw new Error("First argument should be a string representing state of notificaion");
      }
      
    }
  }
})();
/***Notifier.js ends***/





//Extra Code (Implementation)

  //helper function
function $$(selector, context) {
    context = context || document;
    var elements = context.querySelectorAll(selector);
    return Array.prototype.slice.call(elements);
} 

(function() {  
  $$(".btn-notifier").forEach((button)=> {
    button.addEventListener("click", function() {
      
      //fetch data-attributes values
    var state= this.getAttribute("data-not-state"),
        msg= this.getAttribute("data-not-msg"),
        btnText= this.getAttribute("data-not-btn-text"),
        btnAction= this.getAttribute("data-not-btn-action");
      
      
      //fire notification with attributes' data
      Notifier.notify(state, 
                    {
        logo:"https://tympanus.net/Tutorials/AnimatedAnimals/img/link-fox.png", 
        msg: msg,
        actions: [{title: btnText, action: window[btnAction] || console.log}]
      });
         });
  });
})();



function changeTheme() {
   document.body.classList.toggle("dark");
   if(document.body.classList.contains("dark")) {
     triangCon.classList.add("opened");
     main.classList.add("stage-2");
   } else {
     main.classList.remove("stage-2");
   }
 
  Notifier.notify("success", {
    logo:"https://tympanus.net/Tutorials/AnimatedAnimals/img/link-fox.png",
    msg: "Your theme has been changed!"
  });
  
}

function removeTriangles() {
  triangCon.classList.remove("opened");
  
  
   Notifier.notify("success", {
      logo: "https://tympanus.net/Tutorials/AnimatedAnimals/img/link-fox.png",
      msg: "Done! Removed Triangles."
    });
  
  main.classList.remove("stage-2");
}
            
          
!
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