Responsive multi level menu by OnceBuilder
Tags: responsive menu navigation navigation tabbed jquery css rwd multi level menu responsive menu
The MIT License (MIT)
Copyright (c) 2017 OnceBuilder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Copyright (c) 2017 OnceBuilder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,600);
@font-face {
font-family: 'icomoon';
src:url('../fonts/icomoon.eot');
src:url('../fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('../fonts/icomoon.woff') format('woff'),
url('../fonts/icomoon.ttf') format('truetype'),
url('../fonts/icomoon.svg#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
/* minimal styles for that navi */
.rmm {margin: 0 auto;}
.rmm ul {margin: 0; padding:0; list-style: none; position: relative; background: #000;}
.rmm ul:after {content: ""; clear: both; display: block;}
.rmm ul li {float: left;}
.rmm ul li:hover {background: #202020;}
.rmm ul li:hover > ul {display: block;}
.rmm ul li:hover a{color: #fff;}
.rmm ul li a {color: #fff; display: block; text-decoration: none;}
.rmm ul ul {display: none; margin:0; padding: 0; position: absolute; top: 100%;}
.rmm ul ul li {float: none; position: relative;}
.rmm ul ul li a{color: #fff;}
.rmm ul ul li a:hover {background: #202020;}
.rmm ul ul ul {position: absolute; left: 100%; top:0; width: 100%;}
/* mobile menu header button */
.rmm-toggled {width: 100%; background-color: #555555; min-height: 50px; margin: 0 auto; display: none;}
.rmm-closed ~ .rmm-mobile {display: none!important;}
.rmm-toggled-controls{width: 100%;}
.rmm-toggled-title{width: 60%; float: left; font-size: 27px; color: #fff; font-weight:600; display: block; padding: 8px 0; text-decoration: none; text-transform: uppercase; text-align: left; padding-left: 35px;}
.rmm-toggled-button{width: 20%; float: left; margin-top: 3px;
display:block;
width: 32px;
padding:0 !important;
margin:10px 10px 0 0;
border:1px solid #fff;
border-radius:3px;
float: right;
}
.rmm-toggled-button span{float: left; display:block; margin: 3px 6px; height: 3px; background:white; width:20px;}
/* normalny back button visible only on mobiles */
.rmm .rmm-back{display: none; font-size: 12px;}
.rmm .rmm-back:after {display: none;}
.rmm .rmm-back a:after {
font-family: 'icomoon';
speak: none;
-webkit-font-smoothing: antialiased;
content: "\e000";
position: relative;
display: inline-block;
-webkit-transform: rotate(-60deg);
transform: rotate(-60deg);
top: 1px;
right: -2px ;
float: left;
font-size: 10px;
}
.rmm-mobile .rmm-back{display: block;}
/* mobile menu list */
.rmm-mobile{width: 100%;}
.rmm-mobile .rmm-dropdown:hover ~ ul, .rmm-mobile .rmm-dropdown:hover > ul ,.rmm-mobile .rmm-dropdown:hover + ul {display: none!important;}
.rmm-mobile ul{width: 100%; position: inherit!important;}
.rmm-mobile li{width: 100%; }
/* mobile menu js action */
.rmm-dropdown{display: block!important;}
.rmm-mobile .rmm-subview{display: block!important; width: 100%;}
.rmm-mobile .rmm-subover-hidden{display: none!important;}
.rmm-mobile .rmm-subover-visible{display: block;}
.rmm-mobile .rmm-subover-header{display: none!important; padding: 0; margin: 0;}
/* mobile menu content */
.rmm-mobile .rmm-submenu{position: relative; left: 0px;}
.rmm .rmm-mobile li:hover > ul {display: none;}
/* arrow down for wide screen */
.rmm.style {text-align: left; font-family: Tahoma;}
.rmm.style ul {box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15); background:#990; text-transform: uppercase; display: inline-table; text-align:left;}
.rmm.style ul li {text-align:left;}
.rmm.style ul li:hover {background: #4b545f;}
.rmm.style ul ul {display: none; margin:0; background: #5f6975; border-radius: 0px; padding: 0; position: absolute;}
.rmm.style ul li a {color: #fff; font-weight:600; display: block; padding: 15px 35px; text-decoration: none; font-weight:600; }
.rmm.style ul ul li {border-bottom: 1px solid #575F6A; border-top: 1px solid #6B727C;}
.rmm.style ul ul li a {padding: 12px 35px; color: #fff; }
.rmm.style ul ul li a:hover {background: #4b545f;}
/* arrow down for wide screen */
.rmm.style ul li > a:not(:only-child):after {
font-family: 'icomoon';
speak: none;
-webkit-font-smoothing: antialiased;
content: "\e000";
position: relative;
display: inline-block;
-webkit-transform: rotate(210deg);
transform: rotate(210deg);
top: -4px;
left: 1px;
font-size: 10px;
}
/* arrow left for wide screen submenus */
.rmm.style ul ul li > a:not(:only-child):after {-webkit-transform: rotate(120deg)!important; transform: rotate(120deg)!important; top: 2px; font-size: 14px; float: right; margin-right: -20px;}
/* mobile style */
.rmm.style .rmm-mobile li > a:not(:only-child):after {-webkit-transform: rotate(120deg)!important; transform: rotate(120deg)!important; top: 4px!important; font-size: 14px!important; float: right; margin-right: -20px;}
.rmm.style .rmm-mobile li{background: #3ab4a6; border-bottom: 1px solid #575f6a!important; border-top: 0!important; }
/*
like mobile view style
.rmm.style2 {text-align: left; font-family: Tahoma;}
.rmm.style2 ul {box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15); background:#990; text-transform: uppercase; display: inline-table; text-align:left; width: 100%;}
.rmm.style2 ul li {float: none;}
.rmm.style2 ul li:hover {background: #4b545f;}
.rmm.style2 ul ul {display: none; margin:0; background: #5f6975; border-radius: 0px; padding: 0; position: relative;}
.rmm.style2 ul li a {color: #fff; font-weight:600; display: block; padding: 15px 35px; text-decoration: none; font-weight:600; }
.rmm.style2 ul ul li {border-bottom: 1px solid #575F6A; border-top: 1px solid #6B727C;}
.rmm.style2 ul ul li a {padding: 12px 35px; color: #fff; }
.rmm.style2 ul ul li a:hover {background: #4b545f;}
.rmm.style2 ul ul ul {left: 0;}
*/
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// IE 12 => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return false;
}
function adaptMenu() {
/* toggle menu on resize */
$('.rmm').each(function() {
// initialize vars
var maxWidth = 0;
var width = 0;
// width of menu list (non-toggled)
$('.dl-menu').children("li").each(function() {
//console.log($(this).get(0).tagName)
//console.log($(this).parent().get(0).tagName);
if($(this).parent().hasClass('dl-menu')){
width = $(this).outerWidth();//outerWidth();
if(width>0){
maxWidth += width;
}
//console.log(width)
//console.log(maxWidth)
}
//console.log($(this).get(0).clientWidth);//offsetWidth
});
// compare width
var width = $('.rmm').css('max-width');
width = width.replace('px', '');
//console.log($(this).parent().width()+" / "+width)
if ( $(this).parent().width() > width ) {
$('.dl-menu').removeClass("rmm-mobile");
//remove all classes from mobile verion
$(".dl-menu ul").removeClass("dl-subview");
$(".dl-menu li").removeClass("dl-subover-hidden");
$(".dl-menu li").removeClass("dl-subover-visible");
$(".dl-menu a").removeClass("dl-subover-header");
$(".rmm-toggled").removeClass("rmm-closed");
$('.rmm-toggled').hide();
//$('.rmm-toggled').removeClass("rmm-view");
//$('.rmm-toggled').addClass("rmm-closed");
}else {
$('.dl-menu').addClass("rmm-mobile");
$('.rmm-toggled').show();
$('.rmm-toggled').addClass("rmm-closed");
//$('.rmm-toggled').removeClass("rmm-closed");
}
});
}
function resposniveMultiMenu() {
$('.rmm').each(function() {
// create mobile menu classes here to light up HTML
$(this).find("ul").addClass("dl-submenu");
$(this).find("ul:first").addClass("dl-menu");
$(this).find("ul:first").removeClass("dl-submenu");
$(this).find('.dl-submenu').prepend( 'back ' );
if(detectIE()){
$(".dl-menu").children("li").find("a:first").addClass("fixie");
$(this).find("ul").prev().addClass("rmm-dropdown");
}else{
$(this).find("ul").prev().addClass("rmm-dropdown");
}
// initialize vars
var maxWidth = 0;
var width = 0;
// sometimes jquyery doesnt get clientWidth with propertly after refresh f5 ???
// width of menu list (non-toggled)
$('.dl-menu').children("li").each(function() {
//console.log($(this).get(0).tagName)
//console.log($(this).parent().get(0).tagName);
if($(this).parent().hasClass('dl-menu')){
width = $(this).outerWidth();//outerWidth();
if(width>0){
maxWidth += width;
}
console.log(width)
}
//console.log($(this).get(0).clientWidth);//offsetWidth
});
//console.log(maxWidth)
if ($.support.leadingWhitespace) {
$(this).css('max-width' , maxWidth*1.05+'px');
}else{
$(this).css('width' , maxWidth*1.05+'px');
}
// create dropdown button
var str=''
str+=''
str+=''
str+='Menu';
str+=' ';
str+='';
str+='';
$(this).prepend(str);
});
// click interacts in mobile wersion
$('.rmm-dropdown').click(function (e) {
if($('.dl-menu').hasClass('rmm-mobile')){
//e.preventDefault();
//e.stopProgragation();
$(this).next().addClass("dl-subview");
var index=$(this).parent().index();
var i=0;
$(this).parent().parent().children("li").each(function() {
if(index==$(this).index()){
$(this).removeClass("dl-subover-hidden");
$(this).addClass("dl-subover-visible");
}else{
$(this).removeClass("dl-subover-visible");
$(this).addClass("dl-subover-hidden");
}
});
$(this).addClass("dl-subover-header");
}
});
// click back interacts in mobile version
$('.dl-back a').click(function () {
$(this).parent().parent().prev().removeClass("dl-subover-header");
$(this).parent().parent().removeClass("dl-subview");
$(this).parent().parent().parent().parent().find("li").removeClass("dl-subover-hidden");
});
// click toggler interacts in mobile version
$('.rmm-toggled, .rmm-toggled .rmm-button').click(function(){
if ( $(this).is(".rmm-closed")) {
$(this).find('ul').stop().show(300);
$(this).removeClass("rmm-closed");
}else {
$(this).find('ul').stop().hide(300);
$(this).addClass("rmm-closed");
}
});
}
jQuery(window).load(function() {
resposniveMultiMenu();
adaptMenu();
});
$(window).resize(function() {
adaptMenu();
});