<div class="navigation-sub__container">
<nav class="navigation-sub l-container__inner">
<ul class="navigation-sub__inner">
<li class="navigation-sub__item"><a class="navigation-sub__link" href="">What we do</a></li>
<li class="navigation-sub__item navigation-sub__item--active"><a class="navigation-sub__link" href="">Our Work</a></li>
<li class="navigation-sub__item"><a class="navigation-sub__link" href="">Our People</a></li>
<li class="navigation-sub__item"><a class="navigation-sub__link" href="">Our Partners</a></li>
</ul>
</nav>
</div>
<div class="navigation-sub__container">
<nav class="navigation-sub l-container__inner">
<ul class="navigation-sub__inner">
<li class="navigation-sub__item"><a class="navigation-sub__link" href="">What we do</a></li>
<li class="navigation-sub__item navigation-sub__item--active"><a class="navigation-sub__link" href="">Our Work</a></li>
<li class="navigation-sub__item"><a class="navigation-sub__link" href="">Our People</a></li>
<li class="navigation-sub__item"><a class="navigation-sub__link" href="">Our Partners</a></li>
</ul>
</nav>
</div>
{
"title": "Main Navigation",
"items": [
{
"name": "Home",
"active": false,
"sub2": [
{
"name": "Sub Item 1"
},
{
"name": "Sub Item 2"
},
{
"name": "Sub Item 3"
}
]
},
{
"name": "About",
"active": true
},
{
"name": "Projects",
"active": false
},
{
"name": "Outputs",
"active": false
},
{
"name": "Contact",
"active": false
}
]
}
/*======================
These are Site specific styles for hamburger nav. For the actual vendor styles for the hamburger menu and animation, see ./scss/vendors/hamburger
======================*/
.hamburger {
* {
pointer-events: none;
}
&__wrapper {
position: absolute;
display: flex;
right: 0;
align-items: center;
top: calc($elem-pad - 10px);
@include mappy-bp(small) {
display: none;
}
}
&__text {
padding:$hamburger-padding-x 0 $hamburger-padding-x 0;
//display: none;
// @include mappy-bp(rem(425)) {
// Uncomment if you need to hide the hamburger MENU text on small screens
// display: block;
// }
}
}
.navigation-sub {
&__container {
display: none;
justify-content: center;
background-color: setcolor(5);
width: 100%;
padding:0 $elem-pad-sm;
@include mappy-bp(small) {
display: flex;
}
@include mappy-bp(max) {
padding:0;
}
}
&__inner {
display: flex;
font-weight: 700;
}
&__item {
margin-right: rem(50);
color: setcolor(1);
&--active {
color: setcolor(2);
}
}
&__link {
display: block;
padding:rem(7) 0;
color: inherit;
}
}
// .navigation__item {
// &--has-sub {
// position: relative;
// &:hover {
// .sub_navigation {
// visibility: visible;
// opacity: 1;
// margin-top: 0;
// transform: translateY(0);
// }
// }
// }
// }
// .sub_navigation {
// min-width: 200px;
// opacity: 0;
// margin: 0;
// padding: 0;
// position: absolute;
// top: 100%;
// left: 0;
// transition: all 0.2s ease;
// transform: translateY(20px);
// visibility: hidden;
// z-index: 1000;
// border-top: 1px solid #6C60FE;
// .sub_navigation__item {
// &:hover {
// .sub_navigation__link {
// color: setcolor(2);
// }
// }
// }
// }
.navigation {
@include mappy-bp(small) {
display: block;
}
.navigation__inner {
@include mappy-bp(small) {
display: flex;
}
}
&__wrapper {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: $elem-pad-xsm;
@include mappy-bp(small) {
justify-content: flex-start;
margin-bottom: 0;
}
}
&__item {
font-weight: $fnt-weight-bold;
color: setcolor(1);
text-align: center;
@include mappy-bp(small) {
text-align: left;
}
&:hover {
.navigation__link {
color: setcolor(2);
}
}
&--active{
.navigation__link {
position: relative;
&:before {
position: absolute;
width: calc(100% - $elem-pad );
content: '';
border-bottom: 5px solid setcolor(2);
bottom: -10px;
}
}
}
a {
display: block;
transition: color .5s;
color: inherit;
text-decoration: none;
padding:5px 0;
@include mappy-bp(small) {
padding:0 $elem-pad;
}
&:first-of-type {
padding-left: 0;
}
}
}
&__container {
display: none;
&[aria-hidden='true'] {
display: flex;
}
@include mappy-bp(small) {
display: flex !important;
}
.header__cols {
flex-direction: column;
align-items: center;
@include mappy-bp(small) {
flex-direction: row;
}
}
}
}
class Menu {
constructor(elem) {
this.elem = elem;
this.hamburgerId = 'mobileNav';
this.hamburgerElem = document.getElementById(this.hamburgerId);
}
openMenu = false;
cssroot = document.querySelector(':root');
cssVarGet(prop) {
const rootstyles = getComputedStyle(this.cssroot);
const styleVal = rootstyles.getPropertyValue(prop);
return styleVal;
}
cssVarSet(prop, value) {
this.cssroot.style.setProperty(prop, value);
}
setSubMenuHeight() {
let childrenTotal = 0;
document.querySelectorAll('.o-navigation__sub-items').forEach((menu) => {
if (menu.children.length > childrenTotal) {
childrenTotal = menu.children.length;
}
});
const menuheight = ((childrenTotal + 1) * 63) - 50;
this.cssVarSet('--menuheight', `${menuheight}px`);
}
addEventListener() {
this.elem.forEach((btn) => {
if (btn.classList.contains('o-navigation__item-toggle')) {
btn.nextElementSibling.addEventListener('focusout', (e) => {
this.toggleFocus(e);
});
btn.nextElementSibling.addEventListener('focusin', (e) => {
this.toggleFocus(e);
});
}
btn.addEventListener('click', () => {
this.toggleSubmenu(btn.nextElementSibling);
});
btn.addEventListener('keydown', (e) => {
this.keyDown(e);
});
});
}
toggleFocus(e) {
if (e.type === 'focusout') {
if (!e.currentTarget.contains(e.relatedTarget)) {
this.toggleSubmenu(e.currentTarget);
}
}
}
toggleSubmenu(elem) {
const menu = elem;
const btn = elem.previousElementSibling;
if (btn === this.hamburgerElem) {
// It's the main burger menu
if (btn.querySelector('.o-hamburger__btn').classList.contains('is-active')) {
// menu already open, lets close it and reset menus.
this.resetMenu();
return;
}
btn.querySelector('.o-hamburger__btn').classList.toggle('is-active');
document.body.classList.add('js-menu--open');
}
const expanded = menu.getAttribute('aria-hidden') === 'true' || false;
menu.setAttribute('aria-hidden', !expanded);
btn.setAttribute('aria-expanded', expanded);
if (menu.hidden) {
btn.classList.add('js-menu--expanded');
} else {
btn.classList.remove('js-menu--expanded');
}
menu.hidden = !menu.hidden;
}
keyDown(e) {
const keyCode = e.code;
switch (keyCode) {
case 'Escape': // arrow down
e.preventDefault();
this.resetMenu();
break;
default:
}
}
resetMenu() {
// Reset the buttons
this.elem.forEach((btn) => {
btn.setAttribute('aria-expanded', false);
btn.classList.remove('js-menu--expanded');
const menu = btn.nextElementSibling;
menu.hidden = true;
menu.setAttribute('aria-hidden', true);
if (btn.querySelector('.hamburger')) {
document.body.classList.remove('js-menu--open');
btn.querySelector('.hamburger').classList.remove('is-active');
}
});
}
resetBtns(current) {
this.elem.forEach((btn) => {
if (btn !== current && btn.classList.contains('o-navigation__item-toggle')) {
btn.setAttribute('aria-expanded', false);
btn.classList.remove('js-menu--expanded');
const menu = btn.nextElementSibling;
menu.hidden = true;
}
});
}
init() {
this.addEventListener();
this.setSubMenuHeight();
}
}
export default Menu;
No notes defined.