Ace responsive menu is a lightweight jQuery plugin to create responsive multi-level navigation menus with multi device support. Ace responsive menu comes with 3 variants like horizontal, vertical and accordion menu. It gives complete responsive menu solution for any kind of websites or admin templates. The plugin has clean and well commented valid code, easy to Integrate and modify.
Features
Fully Responsive multi-level Menu
Menu Styles: Horizontal, Vertical and Accordion menu
4-Level Menu support
Icon Support [Integrated with FontAwesome]
Click / Hover Events
Lightweight jQuery script
Valid HTML5 and CSS3
Bootstrap Compatible
Easy to Integrate & customize
Cross-browser support
Clean and well commented code
You can get it from here
https://github.com/samsono/Ace-Responsive-Menu
or simply embed the following into your website
1 |
!function(e){e.fn.aceResponsiveMenu=function(s){var i=s=e.extend({resizeWidth:"768",animationSpeed:"fast",accoridonExpAll:!1},s),l=i.resizeWidth,n=i.animationSpeed,a=i.accoridonExpAll,t=e(this),d=e(this).attr("data-menu-style");function o(){if(e(window).innerWidth()<=l)t.find("li.menu-active").removeClass("menu-active"),t.find("ul.slide").removeClass("slide").removeAttr("style"),t.addClass("collapse hide-menu"),t.attr("data-menu-style",""),e(".menu-toggle").show();else{if(t.attr("data-menu-style",d),t.removeClass("collapse hide-menu").removeAttr("style"),e(".menu-toggle").hide(),"accordion"==t.attr("data-menu-style"))return void t.addClass("collapse");t.find("li.menu-active").removeClass("menu-active"),t.find("ul.slide").removeClass("slide").removeAttr("style")}}return t.find("ul").addClass("sub-menu"),"accordion"==d&&e(this).addClass("collapse"),e(window).innerWidth()<=l&&o(),e(window).resize(function(){o()}),e("#menu-btn").click(function(){t.slideToggle().toggleClass("hide-menu")}),this.each(function(){t.on("mouseover","> li a",function(){if(!0===t.hasClass("collapse"))return!1;e(this).parent("li").siblings().children(".sub-menu").stop(!0,!0).slideUp(n).removeClass("slide").removeAttr("style").stop(),e(this).parent().addClass("menu-active").children(".sub-menu").slideDown(n).addClass("slide")}),t.on("mouseleave","li",function(){if(!0===t.hasClass("collapse"))return!1;e(this).off("click","> li a"),e(this).removeClass("menu-active"),e(this).children("ul.sub-menu").stop(!0,!0).slideUp(n).removeClass("slide").removeAttr("style")}),t.on("click","> li a",function(){if(t.hasClass("collapse"),e(this).off("mouseover","> li a"),e(this).parent().hasClass("menu-active"))e(this).parent().children(".sub-menu").slideUp().removeClass("slide"),e(this).parent().removeClass("menu-active");else{if(1==a)return void e(this).parent().addClass("menu-active").children(".sub-menu").slideDown(n).addClass("slide");e(this).parent().siblings().removeClass("menu-active"),e(this).parent("li").siblings().children(".sub-menu").slideUp().removeClass("slide"),e(this).parent().addClass("menu-active").children(".sub-menu").slideDown(n).addClass("slide")}})})}}(jQuery); |
and for the css
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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
/* Ace Responsive Menu ----------------------------------------*/ a { text-shadow: none; color: #0d638f; } ul { margin: 0px; padding: 0px; } .ace-responsive-menu { list-style: none; margin: 0; padding: 0; background: #333; float:left; width:100%; font-family: 'Roboto', sans-serif; /* border-bottom: 3px solid #FD5025; */ } .ace-responsive-menu li{ list-style: none; } .ace-responsive-menu li ul { display:none; } .ace-responsive-menu > li { display: block; margin: 0; padding: 0; border: 0px; float: left; } .ace-responsive-menu li a { color:#c0c0c0; } .ace-responsive-menu > li > a { display: block; position: relative; margin: 0; border: 0px; padding: 18px 20px 18px 12px; text-decoration: none; font-size: 15px; font-weight: 300; color: #c0c0c0; } .ace-responsive-menu li a i { padding-right: 5px; color: #FF5737; } .ace-responsive-menu > li > a i { font-size: 16px; text-shadow: none; color: #FF5737; } .ace-responsive-menu li ul.sub-menu li a i { padding-right: 10px; } .ace-responsive-menu li.menu-active > a { background: #272727; color:#fff; } .ace-responsive-menu li .menu-active { position: relative; } .ace-responsive-menu > li > a > .arrow:before { margin-left: 15px; display: inline; font-size: 16px; font-family: FontAwesome; height: auto; content: " \276F"; font-weight: 300; text-shadow: none; width: 10px; display: inline-block; transform: rotate(90deg); } .ace-responsive-menu li ul.sub-menu li > a > .arrow:before { content: "\f105" !important; } .ace-responsive-menu > li > ul.sub-menu { display: none; list-style: none; clear: both; margin: 0; position: absolute; z-index: 999; } .ace-responsive-menu li ul.sub-menu { background: #333; } .ace-responsive-menu li ul.sub-menu > li { width: 185px; } .ace-responsive-menu li ul.sub-menu li a { display: block; margin: 0px 0px; padding: 12px 20px 12px 15px; text-decoration: none; font-size: 13px; font-weight: normal; background: none; } .ace-responsive-menu > li > ul.sub-menu > li { position: relative; } .ace-responsive-menu > li > ul.sub-menu > li ul.sub-menu { position: absolute; left: 185px; top: 0px; display: none; list-style: none; } .ace-responsive-menu > li > ul.sub-menu > li ul.sub-menu > li ul.sub-menu { position: absolute; left: 185px; top: 0px; display: none; list-style: none; } .ace-responsive-menu > li > ul.sub-menu li > a > .arrow:before { float: right; margin-top: 1px; margin-right: 0px; display: inline; font-size: 16px; font-family: FontAwesome; height: auto; content: "\f104"; font-weight: 300; text-shadow: none; } /* Menu Toggle Btn ----------------------------------------*/ .menu-toggle { display: none; float: left; width: 100%; background: #333; } .menu-toggle h3 { float: left; color: #FFF; padding: 0px 10px; font-weight: 600; font-size: 16px; } .menu-toggle .icon-bar { display: block !important; width: 18px; height: 2px; background-color: #F5F5F5 !important; -webkit-border-radius: 1px; -moz-border-radius: 1px; border-radius: 1px; -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); margin: 3px; } .menu-toggle .icon-bar:hover { background-color: #F5F5F5 !important; } .menu-toggle #menu-btn { float: right; background: #202020; border: 1px solid #0C0C0C; padding: 8px; border-radius: 5px; cursor: pointer; margin: 10px; } .hide-menu { display: none; } /* Accordion Menu Styles ----------------------------------------*/ ul[data-menu-style="accordion"] { width: 250px; } ul[data-menu-style="accordion"] > li { display: block; margin: 0; padding: 0; border: 0px; float: none !important; } ul[data-menu-style="accordion"] > li:first-child { border-top: 2px solid #FD5025; } ul[data-menu-style="accordion"] li ul.sub-menu > li { width: 100%; } ul[data-menu-style="accordion"] > li > a > .arrow:before { float: right; content: "\f105"; } ul[data-menu-style="accordion"] li.menu-active > a > .arrow:before { content: "\f107" !important; } ul[data-menu-style="accordion"] > li > ul.sub-menu { position: static; } ul[data-menu-style="accordion"] > li > a i { padding-right: 10px; color: #FF5737; } ul[data-menu-style="accordion"] > li > ul.sub-menu > li ul.sub-menu { position: static; } ul[data-menu-style="accordion"] > li > ul.sub-menu > li ul.sub-menu > li ul.sub-menu { position: static; } ul[data-menu-style="accordion"] > li { border-bottom: 1px solid #242424; } ul[data-menu-style="accordion"] li a:hover { background: #272727 !important; } ul[data-menu-style="accordion"] ul.sub-menu li.menu-active > a > .arrow:before { content: "\f107" !important; } /* Vertical Menu Styles ----------------------------------------*/ ul[data-menu-style="vertical"] { width: 200px; } ul[data-menu-style="vertical"] > li { float: none; } ul[data-menu-style="vertical"] > li:first-child { border-top: 2px solid #FD5025; } ul[data-menu-style="vertical"] li ul.sub-menu > li { width: 100%; } ul[data-menu-style="vertical"] > li > a > .arrow:before { float: right; content: "\f105"; } ul[data-menu-style="vertical"] > li.menu-active { position:relative; } ul[data-menu-style="vertical"] > li > ul.sub-menu { position: absolute; left:200px; top:0px; width:200px; } ul[data-menu-style="vertical"] > li > a i { padding-right: 10px; color: #FF5737; } ul[data-menu-style="vertical"]> li > ul.sub-menu > li ul.sub-menu { position: absolute; width:200px; left: 200px; } ul[data-menu-style="vertical"] > li > ul.sub-menu > li ul.sub-menu > li ul.sub-menu { position: absolute; width:200px; left: 200px; } ul[data-menu-style="vertical"] > li { border-bottom: 1px solid #242424; } ul[data-menu-style="vertical"] li a:hover { background: #272727 !important; } /* Responsive Menu Styles ----------------------------------------*/ /*Note: change the max-width asper your requirment and change the same in aceResponsiveMenu({resizeWidth: "768" }) function*/ @media screen and (max-width: 768px) { .demo { width:96%; padding:2%; } ul[data-menu-style="vertical"] , ul[data-menu-style="accordion"], ul[data-menu-style="vertical"] li ul.sub-menu { width: 100% !important; } .ace-responsive-menu { float: left; width:100%; } .ace-responsive-menu > li { border-bottom: 1px solid #242424; float: none; } .ace-responsive-menu li a:hover { background: #272727 !important; } .ace-responsive-menu > li:first-child { border-top: 2px solid #FD5025; } .ace-responsive-menu > li > a i { padding-right: 10px; color: #FF5737; } .ace-responsive-menu > li > a > .arrow:before { float: right; content: " \276F"; font-weight: 300; text-shadow: none; width: 10px; display: inline-block; transform: rotate(90deg); } li.menu-active > a > .arrow:before { content: " \276F"; font-weight: 300; text-shadow: none; width: 10px; display: inline-block; transform: rotate(90deg); } .ace-responsive-menu li ul.sub-menu > li { width: 100%; } .ace-responsive-menu li ul.sub-menu li ul.sub-menu li a { padding-left: 30px; } .ace-responsive-menu li ul.sub-menu li ul.sub-menu li ul.sub-menu li a { padding-left: 50px; } .ace-responsive-menu > li > ul.sub-menu { position: static; } .ace-responsive-menu > li > ul.sub-menu > li ul.sub-menu { position: static; } .ace-responsive-menu > li > ul.sub-menu > li ul.sub-menu > li ul.sub-menu { position: static; } .ace-responsive-menu li ul.sub-menu li.menu-active > a > .arrow:before { content: " \276F"; font-weight: 300; text-shadow: none; width: 10px; display: inline-block; transform: rotate(90deg); } } |
You must attach the nav to the page with the toggler or the trigger button
1 2 3 4 5 6 7 8 9 10 11 |
<!-- Menu Toggle btn--> <nav> <div id="menu-toggler" class="menu-toggle"> <button type="button" id="menu-btn"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <ul id="respMenu" class="ace-responsive-menu" data-menu-style="horizontal"></ul> </nav> |
I do recommend to center the menu Left or Right, and adding arrows to the menu css hierarchy as following
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 |
.menu-toggle { display: none; float: left; width: 100%; background: #333; position: absolute; } .menu-toggle #menu-btn { float: left; background: #202020; border: 1px solid #0C0C0C; padding: 10px; border-radius: 5px; cursor: pointer; margin: 10px; z-index: 999999999; position: fixed; left: 30px; } div#menu-toggler { display: block !important; } ul#respMenu{ position: fixed; z-index: 99999; display: none; } ul#respMenu li > a:after { margin-left: 5px; content: '\25BA'; float: left; width: 46px; display: block; background: transparent; text-align: center; height: 35px; cursor: crosshair; z-index: 99999999999; } ul#respMenu > li > a:after { margin-left: 5px; content: '\25BC'; float: left; width: 46px; display: block; background: transparent; text-align: center; height: 35px; cursor: crosshair; z-index: 99999999999; } ul#respMenu li > a:only-child:after { margin-left: 0; content: ''; float: left; width: 46px; display: block; background: transparent; text-align: center; height: 35px; cursor: crosshair; z-index: 99999999999; } |
now you have to call the UL or the menu that you want to attach it to the responsive menu, first you need to get the menu html content then attach it the to ace Responsive menu as following
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 |
<script type="text/javascript"> jQuery(document).ready(function( $ ) { $("#respMenu").html($("#menu-second-top-menu").html()); $("#respMenu").aceResponsiveMenu({ // Set the same in Media query // slow, medium, fast animationSpeed: 'fast', // Expands all the accordion menu on click accoridonExpAll: true }); }); |
In case you have multilevel menu, and you need to manage the clicks on navigation menu to show and hide menu items and make the link logic clickable, we have a smart trick to divide the nav item into left and right side so once we click on the right side we execute the link href and once we click left we just show and hide the menu 😀
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 |
$("ul#respMenu > li > a").on("click", function(e) { var $div = $(this); var side = e.pageX >= ($div.offset().left + $div.width()/2) ? 'clicked right' : 'clicked left'; if(side == 'clicked right'){ //do nothing }else { e.preventDefault(); if($(this).parent().children( "ul" ).hasClass( "slide" )){ $(this).parent().children( "ul" ).removeClass('slide'); $(this).parent().children( "ul" ).hide(); }else{ $(this).parent().children( "ul" ).addClass('slide'); $(this).parent().children( "ul" ).show(); } } }); $("#respMenu").hide(); |
Here is a complete action of js
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 |
<script type="text/javascript"> jQuery(document).ready(function( $ ) { $("#respMenu").html($("#menu-second-top-menu").html()); $("#respMenu").aceResponsiveMenu({ // Set the same in Media query // slow, medium, fast animationSpeed: 'fast', // Expands all the accordion menu on click accoridonExpAll: true }); $("ul#respMenu > li > a").on("click", function(e) { var $div = $(this); var side = e.pageX >= ($div.offset().left + $div.width()/2) ? 'clicked right' : 'clicked left'; if(side == 'clicked right'){ //do nothing }else { e.preventDefault(); if($(this).parent().children( "ul" ).hasClass( "slide" )){ $(this).parent().children( "ul" ).removeClass('slide'); $(this).parent().children( "ul" ).hide(); }else{ $(this).parent().children( "ul" ).addClass('slide'); $(this).parent().children( "ul" ).show(); } } }); $("#respMenu").hide(); }); </script> |
You might attach this into wordpress header or footer as following
1 2 3 4 5 6 7 8 |
function greenbackend_custom() { ?> <!-- Code--> <?php } add_action('wp_head', 'greenbackend_custom') |
you might add some fancy staff like advanced toggler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
.menuisopened{ background: #8e1313 !important; left: 0px !important; } .menuisopened .top-bar { transform: rotate(45deg); transform-origin: 10% 10%; } .menuisopened .middle-bar { opacity: 0; } .menuisopened .bottom-bar { transform: rotate(-45deg); transform-origin: 10% 90%; } |
1 2 3 4 5 |
$("#menu-btn").toggle(function() { $("#menu-btn").addClass('menuisopened'); }, function() { $("#menu-btn").removeClass('menuisopened'); }); |