Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Import RobotoDraft -->
<link href='//fonts.googleapis.com/css?family=RobotoDraft:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en' rel='stylesheet' type='text/css'>

<!-- This is the lite version of the Material Design Snackbar. Prototype: Here be dragons -->

<h1>Web Starter Kit</h1>
<h2>Material Design Snackbar</h2>

<button id="single" class="paper-button raised-button colored">Single line<div class="ripple"/></button>
<button id="multi" class="paper-button raised-button colored">Multi-line<div class="ripple"/></button>
<button id="singleaction" class="paper-button raised-button colored">Single + action<div class="ripple"/></button>
<button id="multiaction" class="paper-button raised-button colored">Multi + action<div class="ripple"/></button>

<!-- <div class="card paper-shadow-top-z-4" style="position: relative;">
  A Card
</div> -->
<br />
<!--
<div class="paper-snackbar">
  Your message was sent
</div>
<div class="paper-snackbar">
  <button class="action">Dismiss</button>
  Your message was sent
</div>

<div class="paper-snackbar">
  This is a longer message that won't fit on one line. It is, inevitably, quite a boring thing. Hopefully it is still useful.
</div>
<div class="paper-snackbar">
  <button class="action">Dismiss</button>
  This is a longer message that won't fit on one line. It is, inevitably, quite a boring thing. Hopefully it is still useful.
</div>

-->

              
            
!

CSS

              
                /*
  Please note this CSS is currently in   prototype form. We'll implement a cleaned up version in Web Starter Kit.
*/

.paper-snackbar {
  transition-property: opacity, bottom, left, right, width, margin, border-radius;
  transition-duration: 0.5s;
  transition-timing-function: ease;
  font-family: RobotoDraft;
  font-size: 14px;
  min-height: 14px;
  background-color: #323232;
  position: absolute;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  line-height: 22px;
  padding: 18px 24px;
  bottom: 0px;
  opacity: 0;

}

@media (min-width: 640px) {
  .paper-snackbar {
    /*
    Desktop:
      Single-line snackbar height: 48 dp tall
      Minimum width: 288 dp
      Maximum width: 568 dp
      2 dp rounded corner
      Text: Roboto Regular 14 sp
      Action button: Roboto Medium 14 sp, all-caps text
      Default background fill: #323232 100%
    */

    min-width: 288px;
    max-width: 568px;
    display: inline-flex;
    border-radius: 2px;
    margin: 24px;
    bottom: -100px;
    
  }
}

@media (max-width: 640px) {
  .paper-snackbar {
  /*
  Mobile:
    Single-line snackbar height: 48 dp
    Multi-line snackbar height: 80 dp
    Text: Roboto Regular 14 sp
    Action button: Roboto Medium 14 sp, all-caps text
    Default background fill: #323232 100%  
  */
    left: 0px;
    right: 0px;
  }
}

.paper-snackbar .action {
  background: inherit;
  display: inline-block;
  border: none;
  font-size: inherit;
  text-transform: uppercase;
  color: #ffeb3b;
  margin: 0px 0px 0px 24px;
  padding: 0px;
  min-width: min-content;
}




/* Everything from here down is actually just for the demo - the material buttons and card, and various other pieces of styling */

/* Variables */

$blue: #4285f4;
$white: #fff;
$black: #000;
$gray: #ccc;
$button-width: 160px;

$top: 1000;

/* Buttons */
.paper-button {
    position: relative;
    padding: 4px 0;
    margin: 1em;
    width: $button-width;
    overflow: hidden;
    user-select: none;
    color: $black;
    text-transform: uppercase;
    border-radius: 3px;
    outline-color: $gray;
  
    &:hover {
        cursor: pointer;
    }

    .ripple {
        position: absolute;
        width: $button-width * 2;
        height: $button-width * 2;
        background-color: rgba($gray, 0.5);
        left: 0;
        top: 0;
        border-radius: 50%;
        margin-left: - $button-width;
        margin-top: - $button-width;
        transform: scaleX(0) scaleY(0);
        z-index: 9000;
    }
}

.paper-button button, .paper-button input[type="submit"] {
  background: inherit;
  border: none;
  display: block;
  width: 100%;
  height: 100%;
  font-family: 'Roboto';
  font-size: 1em;
  color: $black;
  text-transform: uppercase;
}

.paper-button.colored, .paper-button.colored button {
  color: $blue;
}

.paper-button .ripple {
  background-color: rgba($gray, 0.5);
}

.paper-button.raised-button.colored .ripple {
  background-color: rgba($white, 0.5);
}

.paper-button.raised-button .ripple {
  background-color: rgba($gray, 0.5);
}

.paper-button.raised-button.colored {
   background-color: $blue;
}

.paper-button .raised-button{
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
}

.paper-button.raised-button.colored{
  background: #4285f4;
  color: #fff;
}

.paper-button[disabled] {
    background-color: #EAEAEA !important;
    color: #A8A8A8 !important;
    cursor: auto;
}

.paper-button:hover{
  background-color: #EAEAEA;
}
.paper-button.raised-button.colored:hover{
  background-color: #3367d6;
}

button.paper-button {
  border:0;
  font-family: RobotoDraft, 'Helvetica Neue', Helvetica, Arial;
  font-size: 1em;
  line-height: 25px;
  background-color: $white;
}

.paper-button input[type="submit"] {
  outline-color: $gray;  
}

.paper-button.colored.raised-button input[type="submit"] {
  color: $white;
} 

/** Shadows **/
.paper-shadow-animated.paper-shadow {
  transition: box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.paper-shadow-top-z-1 {
  box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.16);
}

.paper-shadow-bottom-z-1 {
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
}

.paper-shadow-top-z-2 {
  box-shadow: 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.paper-shadow-bottom-z-2 {
  box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2);
}

.paper-shadow-top-z-3 {
  box-shadow: 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}

.paper-shadow-bottom-z-3 {
  box-shadow: 0 12px 15px 0 rgba(0, 0, 0, 0.24);
}

.paper-shadow-top-z-4 {
  box-shadow: 0 25px 55px 0 rgba(0, 0, 0, 0.21);
}



/** Card **/
.card {
 background: white;
  width: 300px;
  height: 300px;
  position: relative;
  margin: 16px;
  border-radius: 2px; 
}








/*Demo specific*/
body {
  margin: 1em;
  background-color: white;
  font-family: RobotoDraft, 'Helvetica Neue', Helvetica, Arial;
}

h2 {
  color: #ccc;
}

h4 {
  margin: 4px;
  padding: 2px;
}


              
            
!

JS

              
                /* This is a prototype */
var createSnackbar = (function() {
  // Any snackbar that is already shown
  var previous = null;
  
/*
<div class="paper-snackbar">
  <button class="action">Dismiss</button>
  This is a longer message that won't fit on one line. It is, inevitably, quite a boring thing. Hopefully it is still useful.
</div>
*/
  
  return function(message, actionText, action) {
    if (previous) {
      previous.dismiss();
    }
    var snackbar = document.createElement('div');
    snackbar.className = 'paper-snackbar';
    snackbar.dismiss = function() {
      this.style.opacity = 0;
    };
    var text = document.createTextNode(message);
    snackbar.appendChild(text);
    if (actionText) {
      if (!action) {
        action = snackbar.dismiss.bind(snackbar);
      }
      var actionButton = document.createElement('button');
      actionButton.className = 'action';
      actionButton.innerHTML = actionText;
      actionButton.addEventListener('click', action);
      snackbar.appendChild(actionButton);
    }
    setTimeout(function() {
      if (previous === this) {
        previous.dismiss();
      }
    }.bind(snackbar), 5000);
    
    snackbar.addEventListener('transitionend', function(event, elapsed) {
      if (event.propertyName === 'opacity' && this.style.opacity == 0) {
        this.parentElement.removeChild(this);
        if (previous === this) {
          previous = null;
        }
      }
    }.bind(snackbar));

    
    
    previous = snackbar;
    document.body.appendChild(snackbar);
    // In order for the animations to trigger, I have to force the original style to be computed, and then change it.
    getComputedStyle(snackbar).bottom;
    snackbar.style.bottom = '0px';
    snackbar.style.opacity = 1;
  };
})();

var longMessage = "This is a longer message that won't fit on one line. It is, inevitably, quite a boring thing. Hopefully it is still useful.";
var shortMessage = 'Your message was sent';

document.getElementById('single').addEventListener('click', function() {
  createSnackbar(shortMessage);    
});

document.getElementById('multi').addEventListener('click', function() {
  createSnackbar(longMessage);    
});

document.getElementById('singleaction').addEventListener('click', function() {
  createSnackbar(shortMessage, 'Dismiss');    
});

document.getElementById('multiaction').addEventListener('click', function() {
  createSnackbar(longMessage, 'Wot?', function() { alert('Moo!'); });    
});






/* This stuff just for ripple effect for buttons. Not part of the Snackbar */


var find = document.querySelectorAll.bind(document);
var buttons = find('.paper-button');

for(i=0; i < buttons.length; i++){
 var button = buttons[i];
    button.addEventListener('click', function(e) {
      
    var bound = this.getBoundingClientRect();
    var x = e.clientX - bound.left;
    var y = e.clientY - bound.top;
      
    var ripple = this.querySelector('.ripple');
      
    if (ripple) {
      TweenLite.set(ripple, {x: x, y: y, scaleX: 0, scaleY: 0, opacity: 1});

      TweenLite.to(ripple, 1.5, {scaleX: 1, scaleY: 1, opacity: 0, ease: Expo.easeOut});
    }
  });
}
              
            
!
999px

Console