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

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

              
                <!--
This is an example of Notifly use only teaching purposes.
-->
<div>
  <label>Notification text</label>
  <textarea id="msg">
    Notifly is cool. ;-)
  </textarea>
</div>
<div>
  <label>Notification display time</label>
  <input type="number" step="1" value="0" id="time">
</div>
<div>
  <label>Display position</label>
  <select id="position">
    <option value="notifly-top-center" selected>At the top, centralized</option>
    <option value="notifly-bottom-right">Bottom right</option>
  </select>
</div>
<button onclick="show()">Show</button>
              
            
!

CSS

              
                /* Main container */

.notifly {
  border: grey solid thin;
  width: 200px;
  height: 0px;
  border-radius: 5px;
  border-top-right-radius: 11px;
  background-color: black;
  color: white;
  position: absolute;
  margin: auto;
  /*transition: width 3s, height 3s;*/
  transition: height 3s;
}
/* Shows the notification with the transition */

.notifly-show {
  /*width: 200px;*/
  height: 50px;
}
/* Hides the notification with the transition */

.notifly-hide {
  /*width: 0px;*/
  height: 0px;
}
/* At the top, centralized */

.notifly-top-center {
  top: 0;
  left: 0;
  right: 0;
}
/* Bottom right */

.notifly-bottom-right {
  bottom: 0;
  right: 0;
}
/* Message container */

.notifly-msg {
  font-family: sans-serif;
  font-size: 10pt;
  padding: 5px 5px 5px 5px;
  float: left;
}
/* Close button */

.notifly-close {
  font-family: sans-serif;
  font-size: 10px;
  color: white;
  border: white 1px solid;
  border-radius: 50%;
  width: 15px;
  height: 15px;
  text-align: center;
  padding: 0 0 0 0;
  position: absolute;
  top: 0;
  right: 0;
  cursor: pointer;
}
/* Mouse over on close button */

.notifly-close:hover {
  color: black;
  background-color: white;
}
              
            
!

JS

              
                /*
Class notification display on web pages.

@param string msg The message notification.
@param integer [Optional] Time, in seconds, to display the notification. The default is 0 (the notification does not close alone, only with the close button).
@param string position [Optional] The CSS class name for positioning.
*/
function notifly(msg, time, position) {
  if (typeof time === undefined) {
    time = 0;
  }

  if (typeof position === undefined) {
    position = 'notifly-top-center';
  }

  var mainEl = document.createElement('div');
  mainEl.className = 'notifly ' + position;

  var msgEl = document.createElement('div');
  msgEl.className = 'notifly-msg';
  msgEl.innerHTML = msg;

  var closeBtn = document.createElement('div');
  closeBtn.className = 'notifly-close';
  closeBtn.innerHTML = 'x';

  mainEl.appendChild(msgEl);
  mainEl.appendChild(closeBtn);
  document.body.appendChild(mainEl);

  var close = function() {
    document.body.removeChild(mainEl);
  };

  setTimeout(function() {
    mainEl.className = mainEl.className + ' notifly-show';
  }, 500);

  closeBtn.addEventListener('click', function(event) {
    mainEl.className = mainEl.className + ' notifly-hide';
    setTimeout(function() {
      close();
    }, 3001); /* I used 3001 milliseconds because the CSS transition time is 3 seconds. This prevents the notification disappears before completion of notification.*/
  });

  if (time > 0) {
    setTimeout(function() {
      mainEl.className = mainEl.className + ' notifly-hide';
      setTimeout(function() {
        close();
      }, 3001); /* I used 3001 milliseconds because the CSS transition time is 3 seconds. This prevents the notification disappears before completion of notification.*/
    }, (time * 1000) + 3000); /* I used 3000 milliseconds because the CSS transition time is 3 seconds. This fixes the duration of the notification, if configured. */
  }
};

/* Function with didactic intention, only to display the notification. */

function show() {
  var msg = document.getElementById('msg').innerHTML;
  var position = document.getElementById('position').value;
  var time = document.getElementById('time').value;

  var notify = new notifly(msg, time, position);
};
              
            
!
999px

Console