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

              
                <a id="notificationMenuButton" 
   class="notification-link">
  <div class="notification">
    <span class="icon-notification-bell"></span>
    <div class="notification-badge">
      <span class="number"></span>
    </div>
  </div>
</a>

<div class="controls">
  <button class="increase" type="button">Increase</button>
  <button class="decrease" type="button">Decrease</button>
  <button class="set" type="button">Set 100</button>
  <button class="hide" type="button">Set 0</button>
</div>
              
            
!

CSS

              
                $white: #fff;
$border-radius: .25rem;
$header-height: 70px;
$header-text-color: $white;
$open-sans: 'Open Sans', sans-serif;
$notification-bg-color: #fff;
$notification-text-color: #F74D4D;
$notification-box-size: 16;
$notification-font-size: $notification-box-size / 2;

html, body{
  height: 100%;
}

body{
  background: linear-gradient(90deg, #4984fc 20%, #039ae5 98%);
    padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  
  button{
    background: $white;
    border: 1px solid transparent;
    padding: 10px 15px;
    border-radius: 8px;
    color: #039ae5;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 1.6px;
    cursor: pointer;
    outline: none !important;
    will-change: color, background, border;
    transition: .2s border ease-in-out, .2s background ease-in-out, .2s color ease-in-out;
      
    &:hover {
      border: 1px solid $white;
      color: $white;
      background: transparent;
    }
  }
}

@mixin clickable-area($w: 50px, $h: 50px) {
  &:after {
    content: '';
    position: absolute;
    width: 50px;
    height: 50px;
    opacity: 0;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

.notification {
  width: 38px;
  height: 38px;
  position: relative;

  &-link {
    position: relative;
    width: 38px;
    height: $header-height;
    cursor: pointer;
    display: block;
    margin: 0 0 20px 0;
    user-select: none;
    @include clickable-area();

    &:hover,
    &:focus {
      .icon-notification-bell:after {
        animation: scale-over 2s ease-out infinite;
      }
    }

    .icon-notification-bell {
      font-size: 28px;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      color: $header-text-color;
      
      &:before,
      &:after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        will-change: transform, opacity;
        background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMSAyMSI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogbm9uZTsKICAgICAgfQoKICAgICAgLmNscy0yIHsKICAgICAgICBmaWxsOiAjZmZmOwogICAgICB9CiAgICA8L3N0eWxlPgogIDwvZGVmcz4KICA8ZyBpZD0iR3JvdXBfMSIgZGF0YS1uYW1lPSJHcm91cCAxIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtNDgwIC0xNjUpIj4KICAgIDxyZWN0IGlkPSJSZWN0YW5nbGVfMSIgZGF0YS1uYW1lPSJSZWN0YW5nbGUgMSIgY2xhc3M9ImNscy0xIiB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDQ4MCAxNjUpIi8+CiAgICA8cGF0aCBpZD0iYmVsbC1vX2NvcHkiIGRhdGEtbmFtZT0iYmVsbC1vIGNvcHkiIGNsYXNzPSJjbHMtMiIgZD0iTTE3LjMsMTUuN2wtMi4xLTMuMXYtNGE2LjQyMSw2LjQyMSwwLDAsMC00LjYtNi4xVjEuN0ExLjY4NSwxLjY4NSwwLDAsMCw4LjksMCwxLjg0NCwxLjg0NCwwLDAsMCw3LjEsMS43di44QTYuNDIxLDYuNDIxLDAsMCwwLDIuNSw4LjZ2My45TC40LDE1LjZhMS42NjksMS42NjksMCwwLDAtLjEsMS44LDEuNjUsMS42NSwwLDAsMCwxLjUuOUg2QTIuOTg4LDIuOTg4LDAsMCwwLDguOCwyMGgwYTMuMDc3LDMuMDc3LDAsMCwwLDIuOC0xLjhoNC4yYTEuODU5LDEuODU5LDAsMCwwLDEuNS0uOUExLjM0OCwxLjM0OCwwLDAsMCwxNy4zLDE1LjdabS0xLDEuMmEuNTUuNTUsMCwwLDEtLjUuM0gxMC43bC0uMS40YTEuOTIyLDEuOTIyLDAsMCwxLTEuOCwxLjNBMS43NSwxLjc1LDAsMCwxLDcsMTcuNmwtLjEtLjRIMS44YS41NS41NSwwLDAsMS0uNS0uMy42MzguNjM4LDAsMCwxLDAtLjZsMi40LTMuNVY4LjZhNS4xMjcsNS4xMjcsMCwwLDEsNC4xLTVsLjUtLjFWMS43YS41LjUsMCwxLDEsMSwwVjMuNWwuNS4xYTUuMTI3LDUuMTI3LDAsMCwxLDQuMSw1djQuM2wyLjMsMy41QzE2LjQsMTYuNSwxNi40LDE2LjcsMTYuMywxNi45WiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoNDgxLjYxNCAxNjUuNSkiLz4KICA8L2c+Cjwvc3ZnPgo=")
      }
      
      &:after{
        opacity: 0;
      }
    }

    .notification-badge {
      position: absolute;
      top: 3px;
      right: 1px;
      background: $notification-bg-color;
      border-radius: 100%;
      overflow: hidden;
      width: #{$notification-box-size}px;
      height: #{$notification-box-size}px;
      border: 2px solid $notification-bg-color;
      will-change: transform, background;
      transition: .2s transform ease-in-out, .2s background ease-in-out;
      transform: scale(0);
      box-sizing: border-box;
      box-shadow: 0 0 0 2px #4984fc;

      &.active {
        transform: scale(1);
      }
      
      &.limit{
        background: $notification-text-color;
      }
    }

    .number {
      display: flex;
      align-items: center;
      justify-content: center;
      position: absolute;
      color: $notification-text-color;
      font-weight: 600;
      font-family: $open-sans, sans-serif;
      font-size: 10px;
      line-height: $notification-box-size;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      text-align: center;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      letter-spacing: -0.5px;
      transform: translate(0, 0) scaleY(1);
      opacity: 1;
      will-change: opacity, transform;
      transition: .3s transform ease-in-out, .3s opacity ease-in-out;

      &.old {
        transform: translate(0, -100%) scaleY(0);
        opacity: 0;
      }

      &.new {
        transform: translate(0, 100%) scaleY(0);
        opacity: 0;
      }
    }
  }
}

@keyframes scale-over {
  0%, 100% {
    transform: scale(1);
    opacity: .7;
  }
  20% {
    transform: scale(1.5);
    opacity: 0;
  }
  20.0001% {
    transform: scale(1);
    opacity: .7;
  }
}
              
            
!

JS

              
                function Badge(selector) {
	this.notificationElement = document.querySelector(selector);
	const oldBackground = getComputedStyle(this.notificationElement.querySelector('.notification-badge')).backgroundColor;

	this.setNumber = (n) => {
		n = n || 0;                                    
		let numberElement = this.notificationElement.querySelector('.number');
		let notificationElement = this.notificationElement.querySelector('.notification-badge');
		let newNumberElement = numberElement.cloneNode();

		if (typeof n != 'number' || n < 0 || isNaN(n)) {
			console.error('Wrong type or n(' + n + ') is less then 0!');
			notificationElement.classList.remove('active');
			numberElement.innerHTML = '';

			return false;
		}

		if (n === 0) {
			notificationElement.classList.remove('active');
			numberElement.innerHTML = '';

			return false;
		}

		if (n > 99) {
			notificationElement.classList.add('limit');
		}else{
			notificationElement.classList.remove('limit');
		}

		if (!notificationElement.classList.contains('active')) {
			notificationElement.classList.add('active');
		}

    setTimeout(() => {
      newNumberElement.innerHTML = n;
      newNumberElement.classList.add('new');
      numberElement.classList.add('old');
      numberElement.after(newNumberElement);
      newNumberElement.classList.remove('new');
    }, 0);
    setTimeout(() => {
      numberElement.remove();
    }, 300);
	};

	this.getNumber = () => {
		let numberElement = this.notificationElement.querySelector('.number');
		let n = parseInt(numberElement.innerHTML);
		return typeof n != 'number' ? 0 : n;
	};

	this.increase = (n) => {
		n = n || 1;
		let current = this.getNumber() || 0;

		if (current + n < 0) {
			return false;
		}

		this.setNumber(current + n);
	};

	this.decrease = (n) => {
		n = n || 1;
		let current = this.getNumber() || 0;

		if (current - n < 0) {
			return false;
		}

		this.setNumber(current - n);
	};
}

window.notification = new Badge('.notification');


document.querySelector('.increase').addEventListener('click', () =>  {notification.increase()});
document.querySelector('.decrease').addEventListener('click',  ()=> {notification.decrease()});
document.querySelector('.set').addEventListener('click', () => {notification.setNumber(100)});
document.querySelector('.hide').addEventListener('click', () => {notification.setNumber(0)});
              
            
!
999px

Console