Animated - Hamburger Icon (SVG)

In this example below you will see how to do a Animated - Hamburger Icon (SVG) with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by matchboxhero, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright matchboxhero ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Animated - Hamburger Icon (SVG)</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="container">
	<a href="#" class="menu-button [ js-menu-button ]">
	    <svg class="menu-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
		  <g fill="none" fill-rule="evenodd" stroke="#979797">
		    <path d="M13,26.5 L88,26.5"/>
		    <path d="M13,50.5 L88,50.5"/>
		    <path d="M13,50.5 L88,50.5"/>
		    <path d="M13,74.5 L88,74.5"/>
		  </g>
		</svg>
	</a>
</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/matchboxhero/animated-hamburger-icon-svg-boJdBp */
.container {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ededed;
  min-height: 100vh;
}

.menu-icon {
  position: relative;
  max-width: 5.5rem;
  max-height: 4.125rem;
  width: 100%;
  height: 100%;
  display: inline-block;
}

.menu-icon path {
  stoke: #363636;
  stroke-width: 5;
  stoke-linecap: round;
  transition: all 250ms ease-in-out;
  -webkit-transform: rotate(0deg);
          transform: rotate(0deg);
  -webkit-transform-origin: 50% 50%;
          transform-origin: 50% 50%;
  will-change: transform, opacity;
}

.menu-button:hover path,
.menu-button:focus path,
.menu-button:active path {
  stroke: #D00251;
}

.menu-icon.is-active path:nth-child(1) {
  opacity: 0;
}

.menu-icon.is-active path:nth-child(4) {
  opacity: 0;
}

.menu-icon.is-active path:nth-child(2) {
  -webkit-transform: rotate(45deg);
          transform: rotate(45deg);
}

.menu-icon.is-active path:nth-child(3) {
  -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
}


/*Downloaded from https://www.codeseek.co/matchboxhero/animated-hamburger-icon-svg-boJdBp */
function updateMenuButton() {
	$('.js-menu-button').find('.menu-icon').toggleClass('is-active');
}

$(document).ready(function() {

	$('.js-menu-button').click(function(e){

		e.preventDefault();
		updateMenuButton();

	});

});

Comments