Two Ways to Create an Animated Hamburger Menu

If you’re a developer or a designer, you’re probably familiar with the trend of using hamburger (or three-line) menus as fully responsive and mobile friendly navigation solutions. The trend has grown considerably over time and is becoming even more popular as mobile friendly and mobile first design becomes the norm. In fact, it feels like hamburger menus or three line icons have become a universally recognizes symbol for “navigation menu.” So how do you make yours stand out from the pack? Add some smooth animations, of course! What follows are two different ways to create unique hamburger menus that have animated effects when they’re clicked.

Three Lines to One Line Effect

One cool way to animate your hamburger menu icon is to have the three lines transform into one line when it’s clicked, then have it go back to three lines when it’s clicked again. This can be achieved pretty easily by creating each line of the hamburger menu from HTML and CSS, then creating classes that can be toggled with a jQuery toggle event that will effectively hide the top and bottom menu line when they’re clicked.

Here’s the HTML to start you off:


<div class="icon-group">
<div class="icon"></div>
</div>

As you can see, this icon is created purely from divs. Here’s the CSS you’ll need to use to make those divs look like a three line icon (and to give them some nice style as well!).


.icon-group {
 position: relative;
 width: 65px;
 height: 40px;
 transform: translate(-50%, -50%);
 position: absolute;
 left: 50%;
 top: 50%;
}
.icon-group:hover {
 cursor: pointer;
}

.icon {
 margin-top: 20px;
 position: absolute;
 width: 100%;
 height: 0.5em;
 background: #DB324D;
}
.icon:before, .icon:after {
 position: absolute;
 width: 100%;
 height: 0.5em;
 background: #DB324D;
 transition: margin-top 150ms;
 content: "";
 display: block;
 margin-top: -20px;
}
.icon:after {
 margin-top: 20px;
}

.icon-group.collapsed .icon:before {
 margin-top: 0;
}
.icon-group.collapsed .icon:after {
 margin-top: 0;
}

Your menu icon should now look like this:

Screen Shot 2016-09-23 at 12.40.41 PM

To add the animations, you’ll need to include the following JavaScript:


$(document).ready(function(){
$('.icon-group').on('click', function(){
 $(this).toggleClass('collapsed');
});
});


The code above will toggle the .collapsed class when the .icon-group icon is clicked — this class, when added to the .icon-group div, will actually toggle the top and bottom lines of the icon (this is because of the way we’ve defined them in the CSS — check out .collapsed in the CSS above!). The menu, when clicked, should look like just one line:

Screen Shot 2016-09-23 at 12.40.47 PM

 

Three Lines to X Effect

Another interesting way to animate your three-line hamburger icon menu is to have the three lines transform into an X when it’s clicked. This can be achieved in almost the same was as the previous effect, by having jQuery toggle a particular class when the menu is clicked. To make the lines appear to cross, all you need to employ is the transform property.

Start by creating the elements of your hamburger three-line menu as HTML elements within an <a> tag.

Then style it using the following CSS so that it actually looks like a three-line menu icon:


.hamburgler {
 width: 300px;
 height: 300px;
 display: block;
 -webkit-transition: .3s ease all;
 transition: .3s ease all;
}
.hamburgler.no-hamburgler {
 -webkit-transform: rotate(-45deg);
 transform: rotate(-45deg);
}

.bun,
.meat {
 display: block;
 width: 100%;
 background: #fcd455;
 height: 20%;
 -webkit-transition: .3s ease all;
 transition: .3s ease all;
 border-radius: 50px;
}

.no-hamburgler .top {
 height: 38%;
 width: 20%;
 margin-left: 40%;
 border-radius: 50px 50px 0 0;
}

.no-hamburgler .bottom {
 height: 38%;
 width: 20%;
 margin-left: 40%;
 border-radius: 0 0 50px 50px;
}

.meat {
 margin: 20% 0;
}
.no-hamburgler .meat {
 margin: 2% 0;
}

Your three-line hamburger menu should look like this:

Screen Shot 2016-09-23 at 5.19.05 PM

Use the following JavaScript code to make sure your icon forms an X when it’s clicked:


$(document).ready(function() {
 $('.hamburgler').click(function(e) {
 e.preventDefault();
 $(this).toggleClass('no-hamburgler');
 });

 

Screen Shot 2016-09-23 at 5.19.11 PM

Make sure you include the e.preventDefault(); function or the hamburgler menu will act as a regular link when you click it and could potentially reload the page.

Adding these animations to your hamburger menu icons can really make your icons stand out. In a world where practically everyone is implementing hamburger menus in their designs, it definitely doesn’t hurt to stand out a bit.

 

 

HTML5 Fullscreen Background Video with CSS and JS (Plugin/Library)

Fullscreen background videos that autoplay right when the webpage loads (above the fold) has become quite a popular trend these days. Personally I think a fullscreen good quality video that autoplays does increases engagement for the users/customers. It should be kept in mind that the story of the video must be relevant to the brand. These days we’re surrounded by loads of videos on social networks like FB and Twitter as well which autoplay (but is muted of course). Analytical studies have also reported higher engagement due to this.

Continue reading “HTML5 Fullscreen Background Video with CSS and JS (Plugin/Library)”

Guide (Introduction, Implementation and How it Works) to A/B Testing and Split URL Testing (VWO, Optimizely, Google Analytics)

Recently I’ve been investing a lot of time into A/B (split) testing/experiments and analysing their results. Slowly I’ve started to love this way of rolling out changes on the web (can be surely used for mobile apps as well), as it is a complete data-driven approach and can produce quite surprising (or shocking, how you see it) results at times. With this approach you’ll always know what works (instead of speculating) with firm evidence and eventually drive more sales or signups or whatever that matters to you. That said, I would recommend not A/B testing just anything and everything but always find the right situations or cases that would make sense to experiment. If you’ve enough bandwidth (extra time) then use this approach to keep on analysing your visitor behaviour and draw learnings that help you make more prospects achieve the objectives that you’ve set for them, eventually turning them into customers.

Continue reading “Guide (Introduction, Implementation and How it Works) to A/B Testing and Split URL Testing (VWO, Optimizely, Google Analytics)”

Getting Started with React – Setting up the Development Environment

React (also React.js or ReactJS) is a JavaScript library for building user interfaces developed by Facebook & Instagram. It is not a full blown framework like Angular or Ember or even Backbone.js. It is a very simple View library which can replace the V in any other client-side MVC framework, i.e., you can use Backbone and React together for instance. In fact a lot of people are already doing that. Although when combined with a design pattern like Flux, you can totally give up on an MVC framework for your client-side architecture and happily develop apps with just React in conjunction with the Flux application architecture. React encompasses some interesting concepts too like Virtual DOM, uni-directional reactive data flow, etc. but don’t worry we’ll discuss all those much later when you’re already comfortable with the library and hacking your way through it.

Continue reading “Getting Started with React – Setting up the Development Environment”

Compiling Next Generation JavaScript (ES6, ES7, React) in Browser with Babel 6 and Above

Babel is an amazing tool for writing ES6 (ES2015), ES7 (ES2016), JSX, etc. code that finally gets compiled (or transpiled) into JavaScript (mostly ES5 as of now) that can be executed by most browsers. So basically you can use JS features like classes, promises, etc. without worrying about the browser support as Babel will eventually convert all your code into browser-understandable program.

Continue reading “Compiling Next Generation JavaScript (ES6, ES7, React) in Browser with Babel 6 and Above”

CSS Apply Filter Effects (blur, grayscale, hue) to the Area Behind an Element with backdrop-filter Property

We’re well acquainted with the CSS3 filter property that lets us apply various effects like blur, grayscale, sepia, saturation, etc. to a particular element. Now using this property we actually end up adjusting the rendering of the entire element including its borders, background and content (text or/and image). Did you ever want to apply the same effects to just the area behind the element, i.e., the background of the parent element or the one right behind/below the target element ? This is now very easily possible with the backdrop-filter property. I’m sure you’d have noticed this effect being widely used in iOS 7 and OS X Yosemite.

Continue reading “CSS Apply Filter Effects (blur, grayscale, hue) to the Area Behind an Element with backdrop-filter Property”

Custom Validation Messages for HTML5 Form Constraints

Well, we already know that with HTML5 from constraints, client side form validation has become super easy. All we have to do is use attributes like required, maxlength, pattern, step, etc. and/or the correct form type like email, phone, number, etc. and then once the user submits the form, the browser prompts invalid messages if the form is not entirely valid. Although it might not really be a requirement but from a coolness perspective I thought I’ll share the fact that the error messages can be customized.

Continue reading “Custom Validation Messages for HTML5 Form Constraints”