How we can create a hamburger menu transformation with material design? Solution: See this Material Hamburger Menu Transform Effect, Side Menu Transformation.
Previously I have shared some hamburger related programs, but this is a hamburger menu transformation with material design. Basically, the hamburger is a menu with three rectangular shapes layer, like a real hamburger. And after transform when menu items reveal, the hamburger icons mostly transforms into a cross or back arrow icon.
Today you will learn to create Side Menu Transformation with material design. Basically, there is a hamburger menu icon, when you will click on it then a slide-out menu will reveal with some menu items. Then the menu icon will transform into a back or left-arrow icon. After clicking the back icon then the program becomes as first, you will see only a menu icon.
So, Today I am sharing the Material Hamburger Menu Transform Effect. There I have used HTML to create the layout and CSS for the design and animation, JavaScript is for toggle open and close function. This is a cool menu program, and it can be used desktop and mobile both you don’t have to create different menu for responsive design. You can use this program on your website, after menu items modification.
If you are thinking now how this menu icon animation actually is, then see the preview given below.
Preview Of Side Menu Transformation
See this video preview to getting an idea of how this menu icon looks like.
Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
- Text to Search Input Animation
- Full Screen Modal Nav
- Twitter Intent Generator
- Material Login & Signup Form
Material Hamburger Menu Transform Effect Source Code
Before sharing source code, let’s talk about it. First I have created a section with a class name container and placed all elements inside it. Inside the main section, I have created 2 more sections. The first section for the menu and back icon, and the second section for the menu icon. Inside the sections, I have placed other elements like buttons and divs. Also in the HTML file, I have linked other files like CSS and JavaScript.
Now using CSS I have placed all the items in the right place, as you can in preview. With CSS first I gave basic values like size, position, margin, padding, etc to the elements. There I have used CSS @keyframe command to create animation. And used transform command to creating the menu icon transformation.
JavaScript handling here the toggle on-off feature on the menu. There I have used document.querySelector fetched the elements and detect clicks using .addEventListener command. I used if{} else{} statements to declare conditions. Left all other things you will understand after getting the codes, I can’t explain all in writing.
For creating this program you have to create 3 files. First file for HTML, second for CSS, and third file for JavaScript. Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>Material Design Hamburger | Webdevtrick.com</title> <link rel="stylesheet" href="style.css"> </head> <body> <section class="container"> <section class="material-design-hamburger"> <button class="material-design-hamburger__icon"> <span class="material-design-hamburger__layer"></span> </button> </section> <section class="menu menu--off"> <div>HOME</div> <div>ABOUT</div> <div>SERVICES</div> <div>CONTACT</div> </section> </section> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ @import url(https://fonts.googleapis.com/css?family=Roboto); body { background: #ff4646; } .container { height: 100%; -webkit-transition: all 300ms ease-in-out; transition: all 300ms ease-in-out; margin: 1em 0; padding: 0; } .background--blur { background: #ff2c2c; } .menu { font-size:2em; font-family: 'Roboto', sans-serif; color: #333; } .menu div { margin: 1em; padding-bottom: 1em; border-bottom: 1px solid #ccc; } .menu div:last-child { border: 0; } .menu--off { position: absolute; left: -60%; width: 60%; display: block; background: #eee; min-height: 600px; height: 125%; margin-top: 1em; -webkit-transition: all 300ms; transition: all 300ms; } .menu--on { left: 0; box-shadow: 8px 8px 20px 0 rgba(0, 0, 0, 0.2); -webkit-transition: all 300ms; transition: all 300ms; } .material-design-hamburger button { display: block; border: none; background: none; outline: 0; } .material-design-hamburger__icon { padding: 3rem 1rem; cursor: pointer; } .material-design-hamburger__layer { display: block; width: 100px; height: 10px; background: #eee; position: relative; -webkit-animation-duration: 300ms; animation-duration: 300ms; -webkit-animation-timing-function: ease-in-out; animation-timing-function: ease-in-out; } .material-design-hamburger__layer:before, .material-design-hamburger__layer:after { display: block; width: inherit; height: 10px; position: absolute; background: inherit; left: 0; content: ''; -webkit-animation-duration: 300ms; animation-duration: 300ms; -webkit-animation-timing-function: ease-in-out; animation-timing-function: ease-in-out; } .material-design-hamburger__layer:before { bottom: 200%; } .material-design-hamburger__layer:after { top: 200%; } .material-design-hamburger__icon--to-arrow { -webkit-animation-name: material-design-hamburger__icon--slide; animation-name: material-design-hamburger__icon--slide; -webkit-animation-fill-mode: forwards; animation-fill-mode: forwards; } .material-design-hamburger__icon--to-arrow:before { -webkit-animation-name: material-design-hamburger__icon--slide-before; animation-name: material-design-hamburger__icon--slide-before; -webkit-animation-fill-mode: forwards; animation-fill-mode: forwards; } .material-design-hamburger__icon--to-arrow:after { -webkit-animation-name: material-design-hamburger__icon--slide-after; animation-name: material-design-hamburger__icon--slide-after; -webkit-animation-fill-mode: forwards; animation-fill-mode: forwards; } .material-design-hamburger__icon--from-arrow { -webkit-animation-name: material-design-hamburger__icon--slide-from; animation-name: material-design-hamburger__icon--slide-from; } .material-design-hamburger__icon--from-arrow:before { -webkit-animation-name: material-design-hamburger__icon--slide-before-from; animation-name: material-design-hamburger__icon--slide-before-from; } .material-design-hamburger__icon--from-arrow:after { -webkit-animation-name: material-design-hamburger__icon--slide-after-from; animation-name: material-design-hamburger__icon--slide-after-from; } @-webkit-keyframes material-design-hamburger__icon--slide { 0% { } 100% { -webkit-transform: rotate(180deg); transform: rotate(180deg); } } @keyframes material-design-hamburger__icon--slide { 0% { } 100% { -webkit-transform: rotate(180deg); transform: rotate(180deg); } } @-webkit-keyframes material-design-hamburger__icon--slide-before { 0% { } 100% { -webkit-transform: rotate(45deg); transform: rotate(45deg); margin: 3% 37%; width: 75%; } } @keyframes material-design-hamburger__icon--slide-before { 0% { } 100% { -webkit-transform: rotate(45deg); transform: rotate(45deg); margin: 3% 37%; width: 75%; } } @-webkit-keyframes material-design-hamburger__icon--slide-after { 0% { } 100% { -webkit-transform: rotate(-45deg); transform: rotate(-45deg); margin: 3% 37%; width: 75%; } } @keyframes material-design-hamburger__icon--slide-after { 0% { } 100% { -webkit-transform: rotate(-45deg); transform: rotate(-45deg); margin: 3% 37%; width: 75%; } } @-webkit-keyframes material-design-hamburger__icon--slide-from { 0% { -webkit-transform: rotate(-180deg); transform: rotate(-180deg); } 100% { } } @keyframes material-design-hamburger__icon--slide-from { 0% { -webkit-transform: rotate(-180deg); transform: rotate(-180deg); } 100% { } } @-webkit-keyframes material-design-hamburger__icon--slide-before-from { 0% { -webkit-transform: rotate(45deg); transform: rotate(45deg); margin: 3% 37%; width: 75%; } 100% { } } @keyframes material-design-hamburger__icon--slide-before-from { 0% { -webkit-transform: rotate(45deg); transform: rotate(45deg); margin: 3% 37%; width: 75%; } 100% { } } @-webkit-keyframes material-design-hamburger__icon--slide-after-from { 0% { -webkit-transform: rotate(-45deg); transform: rotate(-45deg); margin: 3% 37%; width: 75%; } 100% { } } @keyframes material-design-hamburger__icon--slide-after-from { 0% { -webkit-transform: rotate(-45deg); transform: rotate(-45deg); margin: 3% 37%; width: 75%; } 100% { } } |
function.js
The final step, create a JavaScript named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// Code By Webdevtrick ( https://webdevtrick.com ) (function() { 'use strict'; document.querySelector('.material-design-hamburger__icon').addEventListener( 'click', function() { var child; document.body.classList.toggle('background--blur'); this.parentNode.nextElementSibling.classList.toggle('menu--on'); child = this.childNodes[1].classList; if (child.contains('material-design-hamburger__icon--to-arrow')) { child.remove('material-design-hamburger__icon--to-arrow'); child.add('material-design-hamburger__icon--from-arrow'); } else { child.remove('material-design-hamburger__icon--from-arrow'); child.add('material-design-hamburger__icon--to-arrow'); } }); })(); |
That’s It. Now you have successfully created Material Hamburger Menu Transform Effect, Side Menu Transformation. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.
how to achieve transformation on scrolling the page not by clicking hamburger menu