Create a sleek CSS animated hamburger menu for your website

I have created a custom hamburger menu using only css. I am now interested in refining it with flexbox. Currently, my html/css code looks like this:

angular.module("myApp", []).controller("myController", function($scope) {
  $scope.animateHamburger = function() {
    // ANIMATION
    console.log("animate hamburger to cross and back to hamburger");
  }
});
.cAnimatedExpander {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 20px;
  margin-right: 10px;
  cursor: pointer;
}

.cAnimatedExpander span {
  height: 2px;
  width: 20px;
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" class="cAnimatedExpander" ng-click="animateHamburger()">
  <span></span>
  <span></span>
  <span></span>
</div>

Now, I am aiming to enhance the animation using css similar to the one shown in this example (first Slider):

I have come across some helpful tutorials online, but they do not incorporate flexbox which I want to utilize in my solution. Any assistance would be greatly appreciated.

Answer №1

Here is the solution to your issue:

angular.module("myApp", []).controller("myController", function($scope) {
  $scope.animateHamburger = function() {
    // ANIMATION
    console.log("animate hamburger to cross and back to hamburger");
    $scope.isActive = !$scope.isActive;
  }
  
});
.cAnimatedExpander {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 20px;
  margin-right: 10px;
  cursor: pointer;
}

.cAnimatedExpander span {
  height: 2px;
  width: 20px;
  background-color: blue;
  transition-duration: 1s;
}

.cross span.top {
    transform: translate(0px, -4px) rotate(45deg);
    transition-duration: 1s;
    transform-origin: left;
}

.cross span.middle {
  opacity: 0;
  transition-duration: 1s;
}

.cross span.bottom {
    transform: translate(0px, -4px) rotate(-45deg);
    transition-duration: 1s;
    transform-origin: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" ng-class="{'cross': isActive}" class="cAnimatedExpander" ng-click="animateHamburger()">
  <span class="top"></span>
  <span class="middle"></span>
  <span class="bottom"></span>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adding a unique identifier to each row in a Django table allows you to efficiently retrieve the selected radio button from that particular row

When working with django-tables2, I'm attempting to utilize jQuery to identify the selected radio button's row and value. The table consists of three columns, with the third column being a templatecolumn that includes HTML code from buttons.html: ...

utilizing the value within the useState function, however, when attempting to utilize it within this.state, the tab switching feature fails

I am struggling to implement tab functionality in a class component. Even though I'm using this.state instead of useState, the tab switching is not working correctly. I have read the following articles but still can't figure it out: http ...

Tips on closing a ui-bootstrap modal by using the back button on an Android device

I have created a ui-bootstrap modal following the instructions in the ui-bootstrap document. angular.module('ui.bootstrap.demo', ['ui.bootstrap']); angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', f ...

Circular background color on Flexbox items

I am relatively new to Flexbox and am attempting to create a responsive table-based calendar with circular background colors on specific cells. However, I am facing an issue where the backgrounds appear as ovals instead of circles on wider screens due to d ...

Problem arises when attempting to display a div after clicking on a hyperlink

I'm encountering an issue with displaying a div after clicking on a link. Upon clicking one of the links within the initial div, a new div is supposed to appear below it. All tests conducted in jsfiddle have shown successful results, but upon transf ...

Understanding how to customize the error message "error" with error code 500 in jqgrid

I have encountered an issue while using CodeIgniter with jQuery grid. My database has an Index that prevents certain combinations from being inserted. The UNIQUE KEY user_store_index (Stores_idStores,Users_idUsers) ensures that a user and store combination ...

Is there a memory leak issue in AngularJS involving ng-switch? Seeking a resolution to this problem

Through my custom routing method for AngularJS, I have successfully implemented ng-switch to enable multi-level deep linking within my application. View the example here I am struggling to understand why memory usage keeps increasing when switching betwe ...

Steps for transferring data from a mock controller to a directive using Jasmine

Attempting to perform unit testing on a directive using Jasmine: app.directive('helloWorld', function() { return { restrict: 'E', scope: { messages: '=', onSelect: '&' }, template: ...

Managing User Feedback with Ajax, JQuery, and PHP

Imagine you're using ajax to send data. The server processes it (in PHP) and sends back a response that can be captured with complete: function(data) { //WRITE HTML TO DIV $('#somehing').html(data) } The big question is: how can you modify ...

Comparing the Usage of Forward Slash [/] and Space in CSS

I'm a bit confused about when to use certain CSS syntaxes. For instance, I've come across: border: 2px solid red; as opposed to: border-width: 2px; border-style: solid; border-color: red; However, I've also seen: font: 12px/18px; rather t ...

Problem with displaying legends in a stacked bar chart using jqplot

I am encountering a problem with the legend placement on the jqplot stacked bar chart. I want to customize the positioning of the legend, but my changes are not taking effect. What I desire is this: However, what I am currently seeing in the legend is as ...

Creating double borders in CSS with the second border extending all the way to the top of the element

Can you help me figure out how to achieve this effect using CSS? It seems like a simple task: border-top: 1px solid #E2E2E2; border-left: 1px solid #E2E2E2; border-bottom: 1px solid #848484; border-right: 1px solid #848484; Just add: box-shadow: 0.7px ...

JavaScript Loading in Chrome Extension

My extension is designed to eliminate unwanted applications from a user's Facebook news feed. The JavaScript code within the extension includes a <script> tag for tracking statistics such as the number of users and their locations. Unfortunatel ...

Saving iFrame as Image using Codemirror and html2canvas

Here are a few experiments I conducted with html2canvas: Fiddle 1 (Using html2canvas): Fiddle 2 (Using html2canvas without Codemirror): Fiddle 3 (Using html2canvas with Codemirror): Fiddle 4 (Using html2canvas with Codemirror): I recently wante ...

Utilizing Functions Within Arrays and HTML

My latest coding project involves creating a fun program where a button triggers a switch in colors for different images resembling a traffic light. Unfortunately, when I test the program by clicking the button, nothing seems to happen. Check out below fo ...

Guide to positioning text alongside icons with Bootstrap

Struggling to align text next to these icons? Don't worry, we've all been there. Especially with bootstrap - it can be tricky! Can someone please guide me on how to do this? <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstr ...

Select a Date: Input for Date Selection

Is it possible to restrict the selection of certain days using HTML date input validation? Some booking websites have a feature where an interactive calendar only allows users to select specific dates for events, while others are greyed out and cannot be c ...

Show the page links on the custom WordPress theme's home page

This is my first time creating a wordpress theme from scratch and I could use some assistance with tackling two specific challenges involving the WP_Query class and the navigation menu. My goal is to showcase the titles and featured images of pages on the ...

Transferring form data through AJAX for uploading files

My current task involves uploading an image using form data with ajax. I have successfully tested the code below and it is saving the image on my local machine. <form ref='uploadForm' id='uploadForm' action='/tab10/uploadImage& ...

Problem with updating the input value in the array

My attempt to replace the input value when deleting a row is not functioning as expected in this dynamic example. <script src="./edit_files/prototype.js" type="text/javascript"></script> <script src="./edit_files/application.js" type="text/ ...