Notification Animation

In this example below you will see how to do a Notification Animation with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by haibnu, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright haibnu ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Notification Animation</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">

  <link rel='stylesheet prefetch' href='https://cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css'>

      <style>
      /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */
      .wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

.title {
  font: bold 12px sans-serif;
  letter-spacing: 2px;
  text-align: center;
  color: #999;
  margin-bottom: 30px;
}

i {
  display: inline-block;
  vertical-align: middle;
}
i + i {
  margin-left: 30px;
}

.notification-icon {
  position: relative;
  top: 0;
  font-size: 48px;
  background-color: transparent;
  user-select: none;
  color: #666;
  transition: color 150ms;
}
.notification-icon:after {
  content: "";
  position: absolute;
  border: 2px solid #fff;
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 60px;
  background-color: red;
  transition: all 100ms;
  opacity: 0;
}
.notification-icon.active {
  color: black;
  animation: swing 500ms ease-in-out;
}
.notification-icon.active:after {
  opacity: 1;
}

.animate-swing:after {
  top: -12px;
  right: -12px;
}
.animate-swing.active:after {
  top: -3px;
  right: -3px;
}

.animate-swing-bottom:after {
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
}
.animate-swing-bottom.active:after {
  bottom: -16px;
}

@keyframes swing {
  20% {
    transform: rotate3d(0, 0, 1, 15deg);
  }
  40% {
    transform: rotate3d(0, 0, 1, -10deg);
  }
  60% {
    transform: rotate3d(0, 0, 1, 5deg);
  }
  80% {
    transform: rotate3d(0, 0, 1, -5deg);
  }
  to {
    transform: rotate3d(0, 0, 1, 0deg);
  }
}

    </style>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>

</head>

<body>

  <div class="wrap">
	<div class="title">CLICK</div>
	<i class="notification-icon animate-swing mdi mdi-bell-outline" data-icon="mdi-bell-outline" data-active-icon="mdi-bell"></i>
	
	<i class="notification-icon animate-swing-bottom mdi mdi-bell-outline" data-icon="mdi-bell-outline" data-active-icon="mdi-bell"></i>
	
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/haibnu/notification-animation-gGJavm */
.wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

.title {
  font: bold 12px sans-serif;
  letter-spacing: 2px;
  text-align: center;
  color: #999;
  margin-bottom: 30px;
}

i {
  display: inline-block;
  vertical-align: middle;
}
i + i {
  margin-left: 30px;
}

.notification-icon {
  position: relative;
  top: 0;
  font-size: 48px;
  background-color: transparent;
  user-select: none;
  color: #666;
  transition: color 150ms;
}
.notification-icon:after {
  content: "";
  position: absolute;
  border: 2px solid #fff;
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 60px;
  background-color: red;
  transition: all 100ms;
  opacity: 0;
}
.notification-icon.active {
  color: black;
  animation: swing 500ms ease-in-out;
}
.notification-icon.active:after {
  opacity: 1;
}

.animate-swing:after {
  top: -12px;
  right: -12px;
}
.animate-swing.active:after {
  top: -3px;
  right: -3px;
}

.animate-swing-bottom:after {
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
}
.animate-swing-bottom.active:after {
  bottom: -16px;
}

@keyframes swing {
  20% {
    transform: rotate3d(0, 0, 1, 15deg);
  }
  40% {
    transform: rotate3d(0, 0, 1, -10deg);
  }
  60% {
    transform: rotate3d(0, 0, 1, 5deg);
  }
  80% {
    transform: rotate3d(0, 0, 1, -5deg);
  }
  to {
    transform: rotate3d(0, 0, 1, 0deg);
  }
}


/*Downloaded from https://www.codeseek.co/haibnu/notification-animation-gGJavm */
$('.notification-icon').click(function(e) {
	var that = $(this);
	that.toggleClass("active "+ that.attr("data-active-icon") + " " + that.attr("data-icon"));
});

Comments