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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="main">
  <img class="phone" src="https://s3-us-west-2.amazonaws.com/ericodepen/5O4NTpa.png">

  <div class="screen inactive">
    <img class="background" src="https://s3-us-west-2.amazonaws.com/ericodepen/6H8IIYX.gif">
    <div class="notifications"> </div>
  </div>
</div>


              
            
!

CSS

              
                body, html {
  border: 0;
  height: 100%;
  margin: 0;
  padding: 0;
}

/* Containers */
.main {
  display: block;
  margin: 0 auto;
  width: 548px;
}
.phone {
  position: absolute;
  top: 0;
  width: 548px;
  z-index: 0;
}
.screen {
  height: 875px;
  margin: 98px 25px;
  overflow: hidden;
  position: relative;
  width: 500px;
}
.notifications {
  height: calc(100% - 136px);
  margin: 68px 0;
  overflow: hidden;
  position: absolute;
  width: 100%;
  z-index: 2;
}

/* Notifications */
.notification {
  background-color: rgba(245, 245, 245, .8);
  border-top: 1px solid rgba(150, 150, 150, .5);
  box-sizing: border-box;
  max-height: calc(3.5em + 24px);
  overflow: hidden;
  opacity: 1;
  padding: 12px 16px;
  transition: all .4s ease;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  white-space: nowrap;
  width: 100%;
  z-index: 1;
}
.notification:first-child {
  border-top: none;
}
.notification.closed {
  max-height: 0;
  padding: 0 16px;
}
.notification-title {
  font-family: sans-serif;
  font-size: 16px;
  font-weight: bolder;
  margin: 0;
  padding: 0;
  pointer-events: none;
}
.notification-content {
  font-family: sans-serif;
  font-size: 14px;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.screen.inactive .notification {
  border-top: none;
  opacity: 0;
  transition: opacity .3s ease, max-height .3s ease, background-color .3s step-end;
}
.screen.inactive .notification.new {
  background-color: transparent;
  max-height: calc(3.5em + 24px);
  opacity: 1;
  padding: 12px 16px;
}
.screen.inactive .notification > .notification-title,
.screen.inactive .notification > .notification-content {
  color: #fff;
}

/* Background */
.background {
  left: 0;
  height: 100%;
  opacity: 1;
  pointer-events: none;
  position: absolute;
  top: 0;
  transition: opacity .4s ease;
}

.screen.inactive > .background {
  opacity: 0;
  transition: opacity .3s ease;
}

              
            
!

JS

              
                let $screen = document.querySelector('.screen');
let $notifications = document.querySelector('.notifications');

let $parser = new DOMParser();
let $notificationsList = [];
let $inactiveTimeout;

// Background Logic
$screen.addEventListener('click', activateScreen);
function activateScreen() {
  $screen.classList.remove('inactive');
  
  clearTimeout($inactiveTimeout);
  $inactiveTimeout = setTimeout(() => {
    $screen.classList.add('inactive');
  }, 7500);
}

// Notifications interaction
let $clicked = false, $startX, $notification;
document.body.addEventListener('mousedown', e => {
  activateScreen();
  $clicked = true;
  
  if (!e.target.classList.contains('notification')) return;
  $notification = e.target;
  $startX = e.clientX;
});
document.body.addEventListener('mousemove', e => {
  if (!$clicked || !$notification) return;
  $notification.style.marginLeft = `${e.clientX - $startX}px`;
});
document.body.addEventListener('mouseup', e => {
  $clicked = false;
  
  if ($notification == null) return;
  let notification = $notification;
  let left = parseInt(notification.style.marginLeft); // converts `"314px"` to `314`
  if (Math.abs(left) > 200) {
    if (left < 200) {
      notification.style.marginLeft = '-500px';
    } else {
      notification.style.marginLeft = '500px';
    }
    
    // Wait for the margin animation and close the notification
    setTimeout(() => {
      notification.classList.add('closed');
      
      // Wait for the closed animation and remove the notification
      setTimeout(() => $notifications.removeChild(notification), 300);
    }, 300);
    
    // Forget about the removed notification
    let index = $notificationsList.indexOf(notification);
    $notificationsList.splice(index, 1);
  } else {
    notification.style.marginLeft = '0px';
  }
  
  $notication = null;
  $startX = null;
});

// Generating notifications
let templates = [
  `
    <p class="notification-title"><i class="far fa-comments"></i> Message from Mom</p>
    <p class="notification-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut nulla at dolor fermentum suscipit ac ornare orci. Nam nibh diam, facilisis vitae mattis nec, maximus et elit. Donec ut nulla velit. Morbi sagittis enim ac quam sagittis consequat quis nec lectus.</p>
  `,
  `
    <p class="notification-title"><i class="far fa-comments"></i> Message from Dad</p>
    <p class="notification-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut nulla at dolor fermentum suscipit ac ornare orci. Nam nibh diam, facilisis vitae mattis nec, maximus et elit. Donec ut nulla velit. Morbi sagittis enim ac quam sagittis consequat quis nec lectus.</p>
  `,
  `
    <p class="notification-title"><i class="far fa-envelope"></i> New mail from Iroh</p>
    <p class="notification-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut nulla at dolor fermentum suscipit ac ornare orci. Nam nibh diam, facilisis vitae mattis nec, maximus et elit. Donec ut nulla velit. Morbi sagittis enim ac quam sagittis consequat quis nec lectus.</p>
  `,
  `
    <p class="notification-title"><i class="far fa-envelope"></i> New mail from Korra</p>
    <p class="notification-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut nulla at dolor fermentum suscipit ac ornare orci. Nam nibh diam, facilisis vitae mattis nec, maximus et elit. Donec ut nulla velit. Morbi sagittis enim ac quam sagittis consequat quis nec lectus.</p>
  `,
  `
    <p class="notification-title"><i class="far fa-comment"></i> Luke commented on your video</p>
    <p class="notification-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut nulla at dolor fermentum suscipit ac ornare orci. Nam nibh diam, facilisis vitae mattis nec, maximus et elit. Donec ut nulla velit. Morbi sagittis enim ac quam sagittis consequat quis nec lectus.</p>
  `,
  `
    <p class="notification-title"><i class="far fa-comment"></i> BB-8 commented on your photo</p>
    <p class="notification-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut nulla at dolor fermentum suscipit ac ornare orci. Nam nibh diam, facilisis vitae mattis nec, maximus et elit. Donec ut nulla velit. Morbi sagittis enim ac quam sagittis consequat quis nec lectus.</p>
  `
];

setTimeout(createNotification, 500);
setInterval(createNotification, 4500);

function createNotification() {
  if ($notificationsList.length > 15) return;
  
  // Get a random notification
  let index = Math.floor(Math.random() * templates.length);
  let doc = $parser.parseFromString(`<div class="notification new closed">${templates[index]}</div>`, 'text/html');
  
  // Initialize the notification
  let notification = $notifications.appendChild(doc.body.firstChild);
  setTimeout(() => { notification.classList.remove('closed'); }, 10);
  setTimeout(() => { notification.classList.remove('new'); }, 2500);
  
  // Remember the new notification
  $notificationsList.push(notification);
}

              
            
!
999px

Console