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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                  <h1>jQuery Announce</h1>
  <p class="muted">
    A micro-plugin for displaying unobtrusive announcements.
  </p>
  <p>
    These announcements are highly customizable. They ship with very basic styles so you can easily
    override them or write your own. You can even customize the show/hide animation. Check out the
    docs to learn more.
  </p>
  <p>
    <a href="https://github.com/Shadowsith/jquery-announce/">
      Docs, download, and bugs
    </a>
  </p>

  <h2>Examples</h2>
  <p>
    <button type="button" class="info">Info</button>
    <button type="button" class="danger">Danger</button>
    <button type="button" class="warning">Warning</button>
    <button type="button" class="success">Success</button>
    <button type="button" class="primary">Primary</button>
    <button type="button" class="secondary">Secondary</button>
    <button type="button" class="light">Light</button>
    <button type="button" class="dark">Dark</button>
  </p>
  <p>
    <button type="button" class="outline">Outline</button>
    <button type="button" class="bottom">Bottom</button>
    <button type="button" class="left">Left</button>
    <button type="button" class="right">Right</button>
    <button type="button" class="center">Center</button>
  </p>
  <p>
    <button type="button" class="news">New Color</button>
    <button type="button" class="custom">Custom</button>
    <button type="button" class="colors_on">Custom Colors ON</button>
    <button type="button" class="colors_off">Custom Colors OFF</button>
  </p>
              
            
!

CSS

              
                  html {
    box-sizing: border-box;
  }
  *, *:before, *:after {
    box-sizing: inherit;
  }
  body {
    font-family: sans-serif;
    font-size: 16px;
    color: #333;
    padding: 20px;
  }
  h1 {
    margin-top: 0;
  }
  a {
    color: #09d;
  }
  .muted {
    color: #999;
  }
  button {
    border: none;
    border-radius: 4px;
    background: #09d;
    box-shadow: none;
    color: white;
    -webkit-appearance: none;
    padding: 10px 20px;
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
  }
  button:hover,
  button:focus,
  button:active {
    background-color: #08c;
    outline: none;
  }
  button + button {
    margin-left: 10px;
  }

  .announce.announce-custom-1 {
    top: 10px;
    right: 10px;
    left: auto;
    border-radius: 4px;
    background-color: black;
    color: white;
  }

.announce {
  position: fixed;
  z-index: 9999;
  width: 500px;
  left: calc(50% - 250px);
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  text-align: center;
  padding: 20px;
  margin: 0;
  user-select: none;
}

.announce-bottom {
 top: calc(100% - 60px);  
 bottom: 0;
}

.announce-center {
  top: calc(50% - 20px);  
  left: calc(50% - 250px);
}

.announce-border {
  border-style: solid;
  border-width: 2px;
}

.announce-danger {
  color: white;
  background-color: #d9534f;
}

.announce-info {
  color: white;
  background-color: #5bc0de;
}

.announce-success {
  color: white;
  background-color: #5cb85c;
}

.announce-warning {
  color: white;
  background-color: #f0ad4e;
}

.announce-primary {
  color: white;
  background-color: #007bff;
}

.announce-secondary {
  color: white;
  background-color: #aaa;
}

.announce-light {
  color: black;
  background-color: #e6e6e6;
}

.announce-dark {
  color: white;
  background-color: #343a40;
  background-color: #292929;
}

@media screen and(max-width: 500px) {
  .announce {
    width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    left: 0;
  }
}

              
            
!

JS

              
                //
// jQuery.announce - A micro-plugin for displaying unobtrusive announcements.
//
// Developed by Cory LaViska for A Beautiful Site, LLC
//
// Licensed under the MIT license: http://opensource.org/licenses/MIT
//
if(jQuery) (function($) {
  'use strict';

  function create(type, options) {
    let defer = $.Deferred();
    let announcement = $('<div>');
    let timeout;

    if(typeof(options) === 'string') {
      options = { message: options };
    }

    options = $.extend({}, $.announce.defaults, options);

    // Remove existing announcements
    $('.' + options.className).remove();

    // Create the announcement
    $(announcement)
      .addClass(options.className + ' ' + options.className + '-' + type)
      .hide();

    // Hide on click
    if(options.hideOnClick) {
      $(announcement).on('click.announce', function() {
        clearTimeout(timeout);
        options.hide.call(announcement).then(defer.resolve);
      });
    }

    // Set the message
    if(options.html) {
      $(announcement).html(options.message);
    } else {
      $(announcement).text(options.message);
    }

    // Add it to the DOM
    $('body').append(announcement);

    if(options.vPos != 'top') {
      switch(options.vPos) {
        case 'bottom':
          $(announcement).addClass('announce-bottom');
          break;
        case 'center':
          $(announcement).addClass('announce-center');
          break;
      }
    } else {
      $(announcement).css('top', 0);
    }

    if(options.hPos != 'center') {
      switch(options.hPos) {
        case 'left':
          $(announcement).css('left', 0);
          break;

        case 'right':
          $(announcement).css({'left' : 
              `calc(100% - ${$(announcement).width()}px)`});
          break;
        }
    }

    if(options.customColors) {
      let type = $(announcement).prop('class');
      type = type.split(' ')[1].split('-')[1];
      $(announcement).css('background-color', options.colors[type]);
      if(options.colors.text !== options.colors.dark && !options.outline) {
        $(announcement).css('color', options.colors.text);
      }
      else if(type === 'light' || type === 'warning') {
        $(announcement).css('color', options.colors.text);
      }
    }

    if(options.outline) {
      $(announcement).css('color', $(announcement).css('background-color'));
      $(announcement).css('background-color', options.outlineColor);
      $(announcement).addClass('announce-border');
    }

    // Show it
    options.show.call(announcement);

    // Hide after a moment
    timeout = setTimeout(function() {
      options.hide.call(announcement).then(defer.resolve);
    }, options.duration);

    return defer;
  }

  $.announce = {
    // Default options
    defaults: {
      className: 'announce',
      duration: 2000,
      hideOnClick: true,
      html: false,
      customColors: false,
      outline: false,
      outlineColor: 'transparent',
      vPos: 'top',
      hPos: 'center',
      show: function() {
        let defer = $.Deferred();
        $(this).fadeIn(250, function() {
          defer.resolve();
        });
        return defer;
      },
      hide: function() {
        let defer = $.Deferred();
        $(this).fadeOut(250, function() {
          $(this).remove();
          defer.resolve();
        });
        return defer;
      },
      colors: {
          info: '#17a2b8',
          danger: '#dc3545',
          warning: '#ffc107',
          success: '#28a745',
          primary: '#007bff',
          secondary: '#6c757d',
          light: '#f8f9fa',
          text: '#343a40',
          dark: '#343a40'
      }
    },

    // Info
    info: function(options) {
      return create('info', options);
    },

    // Danger
    danger: function(options) {
      return create('danger', options);
    },

    // Success
    success: function(options) {
      return create('success', options);
    },

    // Warning
    warning: function(options) {
      return create('warning', options);
    },

    primary: function(options) {
      return create('primary', options);
    },

    secondary: function(options) {
      return create('secondary', options);
    },

    light: function(options) {
      return create('light', options);
    },

    dark: function(options) {
      return create('dark', options);
    },

    // Custom announcement
    say: function(type, options) {
      return create(type, options);
    }
  };
})(jQuery);

  $(function() {

    $('.info').on('click', function() {
      $.announce.info('It’s dangerous to go alone! Take this.');
    });

    $('.danger').on('click', function() {
      $.announce.danger('Dangerous roads are ahead!');
    });

    $('.success').on('click', function() {
      $.announce.success('We made it out!');
    });

    $('.warning').on('click', function() {
      $.announce.warning('Hey, be careful out there!');
    });

    $('.primary').on('click', function() {
      $.announce.primary('First!');
    });

    $('.secondary').on('click', function() {
      $.announce.secondary('Hey, I am the second one');
    });

    $('.light').on('click', function() {
      $.announce.light('It’s very bright!');
    });

    $('.dark').on('click', function() {
      $.announce.dark('Dark night is coming!');
    });

    $('.outline').on('click', function() {
      $.announce.info({
        message: 'Outline notification',
        outline: true,
        outlineColor: 'white'
      });
    });

    $('.bottom').on('click', function() {
      $.announce.info({
        message: 'Bottom notification',
        vPos: 'bottom'
      });
    });

    $('.left').on('click', function() {
      $.announce.info({
        message: 'Left notification',
        hPos: 'left'
      });
    });

    $('.right').on('click', function() {
      $.announce.info({
        message: 'Right notification',
        hPos: 'right'
      });
    });

    $('.center').on('click', function() {
      $.announce.info({
        message: 'Centered notification',
        vPos: 'center'
      });
    });

    $('.news').on('click', function() {
      $.announce.info({
        message: 'News: Infobox with custom color',
        customColors: true,
        colors: {info: 'purple', text: 'mistyrose'}
      });
    });


    $('.colors_on').on('click', function() {
      $.announce.defaults.customColors = true;
    });

    $('.colors_off').on('click', function() {
      $.announce.defaults.customColors = false;
    });


    // Custom
    $('.custom').on('click', function() {
      $.announce.say('custom-1', {
        message: 'Custom announcements are <em>easy!</em>',
        html: true,
        show: function() {
          var defer = $.Deferred();

          $(this).show(250, function() {
            defer.resolve();
          });

          return defer;
        },
        hide: function() {
          var defer = $.Deferred();

          $(this).hide(250, function() {
            defer.resolve();
          });

          return defer;
        }
      });
    });
  });

              
            
!
999px

Console