Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup old nav script - refactor or delete
function initNavigation(){
//var docElement = document.documentElement;
console.log('init navigation');
var currId,
idTarget,
navCurrent,
buttonOpen = document.querySelectorAll('.js-open-nav'),
topBar = document.querySelectorAll('.top-bar'),
topBarNavButton = topBar.querySelectorAll(buttonOpen),
buttonClose = document.querySelectorAll('.js-close-nav'),
navClass = '.nav',
nav = document.querySelectorAll(navClass),
isOpen = false;
buttonOpen.addEventListener('click', function (e) {
idTarget = this.getAttribute('href');
navCurrent = document.querySelectorAll(navClass + idTarget);
e.preventDefault();
fadeOut(topBarNavButton);
topBar.classList.add('top-bar--active');
toggleMenu(currId, idTarget);
});
buttonClose.addEventListener('click', function (e) {
//$('body').off('.top-bar--active');
idTarget = this.getAttribute('href');
navCurrent = document.querySelectorAll(navClass + idTarget);
e.preventDefault();
toggleMenu(currId, idTarget);
});
}
document.addEventListener('scroll', function() {
if( isOpen ) {
//console.log(idTarget);
toggleMenu(currId, idTarget);
}
});
/* + Temp */
function fadeOut(el){
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= .1) < 0) {
el.style.display = "none";
} else {
requestAnimationFrame(fade);
}
})();
}
function fadeIn(el, display){
el.style.opacity = 0;
el.style.display = display || "block";
(function fade() {
var val = parseFloat(el.style.opacity);
if (!((val += .1) > 1)) {
el.style.opacity = val;
requestAnimationFrame(fade);
}
})();
}
/* = Temp */
module.exports = {
init: initNavigation
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.