Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div class="container">

  <h1>Alert! Alert!</h1>

  <!-- Begin badges -->
  <a href="http://badge.fury.io/js/alert-alert"><img src="https://camo.githubusercontent.com/06fa0f983bdc5ff4fe8093b7abdc7cd85a4c4df161763c987ad95aba344844a5/68747470733a2f2f62616467652e667572792e696f2f6a732f616c6572742d616c6572742e737667" alt="npm version" data-canonical-src="https://badge.fury.io/js/alert-alert.svg" style="max-width:100%;" target="_blank"></a>
  
  <a href="https://travis-ci.org/whusterj/alert-alert"><img src="https://camo.githubusercontent.com/40cab30c307e628b580f66940fdde591cbf4b1c008b7a77bf79ca321dd4111ac/68747470733a2f2f7472617669732d63692e6f72672f776875737465726a2f616c6572742d616c6572742e7376673f6272616e63683d6d6173746572" alt="Build Status" data-canonical-src="https://travis-ci.org/whusterj/alert-alert.svg?branch=master" style="max-width:100%;" target="_blank"></a>
  <!-- End badges -->
  
  <p>A simple JavaScript library for generating growl-style notifications.
     No framework necessary.</p>

  <div>
    <button id="genAlertBtn">Generic Alert</button>
    <button id="infoAlertBtn">Info Alert</button>
    <button id="successAlertBtn">Success Alert</button>
    <button id="warnAlertBtn">Warning Alert</button>
    <button id="errorAlertBtn">Error Alert</button>
  </div>

  <h2>Sample Usage</h2>
  
  <p>Trigger new alerts with this simple API</p>
  
  <pre><code class="javascript">var type = 'info',
    message = '&lt;p&gt;Something you outta know!&lt;/p&gt;',
    config = { timeout: 7000 };
  
Alert.alert(type,message, config);</code></pre>
  
  <p>Alert options include: 'info', 'success', 'warning', and 'error', which are
     color-coded to match their respective status.</p>
  
  <p>Last Updated: Nov 18, 2014</p>
  
</div>

<a href="https://github.com/whusterj/alert-alert" target="_blank">
  <img decoding="async" width="149" height="149"  style="position: absolute; top: 0; right: 0; border: 0;" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png" class="attachment-full size-full" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>

              
            
!

CSS

              
                /**
 * Demo page styles
 */
@import url(https://fonts.googleapis.com/css?family=Abril+Fatface);
@import url(https://fonts.googleapis.com/css?family=Signika);

body {
  font-family: Signika, Arial, Helvetica, sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.40;
  background: rgb(234, 234, 242);
}

h1 {
  font-size: 50px;
}

h2 {
  font-size: 37px;
}

button {
  pointer: cursor;
  padding: 8px;
  border-radius: 6px;
}

.container {
  max-width: 600px;
  margin: 0 auto;
}

/**
 * Alert! Alert! styles
 */
/* variables */
@aa-blue       :  rgb(100, 100, 200);
@aa-green      :  rgb(100, 180, 100);
@aa-yellow     :  rgb(230, 215, 100);
@aa-red        :  rgb(230, 100, 100);
@aa-gray       :  rgb(100, 100, 100);
@aa-darkGray   :  rgb( 60,  60,  60);

@aa-dropShadow :  rgba(0, 0, 0, 0.6);

@aa-zIndex : 1001;

/* styles */

#aa-notificationContainer {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: @aa-zIndex;
}

.aa-notification {
  width: 300px;
  min-height: 40px;
  padding: 12px;
  margin-bottom: 12px;
  background-color: white;
  border-left: 4px solid @aa-gray;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 1px 1px 3px @aa-dropShadow;
  transition: 0.3s linear all;
  
  &:hover {
    transform: scale(1.06);
    box-shadow: 3px 3px 4px @aa-dropShadow;
  }
  
  &.info {
    border-left-color: @aa-blue;
  }
  
  &.success {
    border-left-color: @aa-green;
  }
  
  &.warning {
    border-left-color: @aa-yellow;
  }
  
  &.error {
    border-left-color: @aa-red;
  }
}
              
            
!

JS

              
                /// Library (usage example at bottom) ///

/**
 * Alert! Alert! is a minimalist JavaScript growl-style notification library
 * designed to run in modern browsers without external dependencies.
 *
 * @author  William Huster  <whusterj@gmail.com>
 * @version 1.0.2
 *
 * Usage:
 *
 *     var type    = 'info',
 *         message = '<p>Something you outta know!</p>',
 *         config  = { timeout: 7000 };
 *
 *     Alert.alert(type, message [, config]);
 *
 * @param type: type of alert - 'info', 'success', 'warning', or 'error'
 * @param message: string/html to display in notification
 * @param config: currently only supports 'timeout' - how long to wait before
 *                dismissing the notification.
 */

var Alert = (function () {
  
  var container,
      CONTAINER_ID  = 'aa-notificationContainer',
      ALERT_CLASS   = 'aa-notification',
      INFO_CLASS    = 'info',
      SUCCESS_CLASS = 'success',
      WARNING_CLASS = 'warning',
      ERROR_CLASS   = 'error';
  
  exports = {
    alert: alert
  };
  
  return exports;
  
  /// functions ///
  
  function alert (type, message, config) {
    if (typeof(config) === 'undefined') { config = {}; }
    if (!container) { container = genNotificationContainer(); }
    container.appendChild(
      genAlertDiv(type, message, config.timeout)
    );
  }
  
  function genNotificationContainer () {
    if (container) { return; }
    var containerDiv = document.createElement('div');
    containerDiv.id = CONTAINER_ID;
    document.body.appendChild(containerDiv);
    return containerDiv;
  }
  
  function genAlertDiv (type, message, timeout) {
    var alertDiv = document.createElement('div');
    alertDiv.className = ALERT_CLASS + ' ' + type;
    alertDiv.innerHTML = message;
    
    //
    alertDiv.addEventListener('click', alertClickHandler);

    //
    if (timeout) {
      alertDiv.timeout = setTimeout(
        function () {
          removeAlert(alertDiv);
        }, timeout); 
    }
    
    return alertDiv;
  }
  
  function removeAlert (alert) {
    window.clearTimeout(alert.timeout);
    container.removeChild(alert);
  }
  
  function alertClickHandler (event) {
    removeAlert(event.currentTarget);
  }
  
})();


/// Usage Example ///

var genAlertBtn     = document.getElementById('genAlertBtn'),
    infoAlertBtn    = document.getElementById('infoAlertBtn'),
    successAlertBtn = document.getElementById('successAlertBtn'),
    warnAlertBtn    = document.getElementById('warnAlertBtn'),
    errorAlertBtn   = document.getElementById('errorAlertBtn');

genAlertBtn.addEventListener('click', newAlert);
infoAlertBtn.addEventListener('click', infoAlert);
successAlertBtn.addEventListener('click', successAlert);
warnAlertBtn.addEventListener('click', warnAlert);
errorAlertBtn.addEventListener('click', errorAlert);

function newAlert (type, message, timeout) {
  var type = type || 'info',
      message = message || 'No message given',
      config = {
        timeout: timeout || 7000
      };
  
  // AND HERE'S THE MAGIC:
  Alert.alert(type, message, config);
}

function infoAlert () {
  newAlert('info', '<p>Here\'s some vital info!</p>');
}

function successAlert () {
  newAlert('success', '<p>Waaah! Great success!</p>');
}

function warnAlert () {
  newAlert('warning', '<p>Ah, ah, ah. I wouldn\'t do that!</p>');
}

function errorAlert () {
  newAlert('error', '<p>Woah! Oh noes! Something broke!</p>');
}

// Syntax highlighting for demo
hljs.initHighlightingOnLoad();

              
            
!
999px

Console