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">
  <div class="row">
    <div class="col-md-12">
      
      <div class="messages-server-wrapper">
        <div class="alert alert-warning">
          Server message
        </div>
        <div class="alert alert-warning">
          Server message
        </div>
        <div class="alert alert-info">
          Server message
        </div>
        <div class="alert alert-danger">
          Server message
        </div>
      </div>
      
      <br><br>
      <br><br>
      
      <button class="btn btn-info show-info">show info</button>
      <button class="btn btn-success show-success">show success</button>
      <button class="btn btn-warning show-warning">show warning</button>
      <button class="btn btn-danger show-danger">show danger</button>
    </div>
  </div>
</div>
              
            
!

CSS

              
                .messages-wrapper {
  position: absolute;
  top: 25px;
  left: 15%;
  width: 70%;
  z-index: 2000;
}

.messages-wrapper .message {
  display: none;
}

.messages-wrapper .message.show {
  display: inline;
}

.messages-wrapper .message .alert {
  margin-bottom: 7px;
	box-shadow: 0 0 4px 0 #b6b6b6;
}

.messages-server-wrapper {
  display: none;
}
              
            
!

JS

              
                 var Messages = (function() {
   var Messages = {};

   function messagesWrapper() {
     $(document.body).append('<div class="messages-wrapper"></div>');
   }

   function messageTpl(id, status, message) {
     var html = '<div id="message-' + id + '" class="message"><div class="alert alert-' + status + ' alert-dismissible">';
     html += '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span></button>';
     html += message;
     html += '</div></div>';
     return html;
   }

	 function showMessage(status, message) {
		 var wrapper = $('.messages-wrapper').get(0);

		 if (!wrapper) {
			 messagesWrapper();
		 }

		 var id = getRandomInt();
		 var html = messageTpl(id, status, message);

		 $(".messages-wrapper").prepend(html);
		 //$('#message-' + id).animate({opacity: 1}, 300);
		 $('#message-' + id).addClass('show');
		 $('#message-' + id).velocity("slideDown", { duration: 300 });

		 window.setTimeout(function() {
			 //$('#message-' + id).animate({opacity: 0}, 300, function() {
			 //$('#message-' + id).remove();
			 //});
				$('#message-' + id).velocity("fadeOut", { duration: 500, complete: function() {
					$('#message-' + id).removeClass('show');
			 		$('#message-' + id).remove();
		 		}});
	 		}, 3000);
 		}

   function getRandomInt() {
     return Math.floor(Math.random() * (100 - 0)) + 0;
   }

   Messages.info = function(message) {
     showMessage('info', message);
   }

   Messages.success = function(message) {
     showMessage('success', message);
   }

   Messages.warning = function(message) {
     showMessage('warning', message);
   }

   Messages.danger = function(message) {
     showMessage('danger', message);
   }

   Messages.showServerMessages = function() {
     $('.messages-server-wrapper .alert').each(function(i) {
       if ($(this).is('.alert-info')) {
         Messages.info($(this).text());
       } else if ($(this).is('.alert-success')) {
         Messages.success($(this).text());
       } else if ($(this).is('.alert-warning')) {
         Messages.warning($(this).text());
       } else if ($(this).is('.alert-danger')) {
         Messages.danger($(this).text());
       }
     });
   }

   return Messages;
 }());

 $('.show-info').click(function() {
   Messages.info('Info!');
 });

 $('.show-success').click(function() {
   Messages.success('Success!');
 });

 $('.show-warning').click(function() {
   Messages.warning('Warning!');
 });

 $('.show-danger').click(function() {
   Messages.danger('Danger!');
 });

 Messages.showServerMessages();
              
            
!
999px

Console