Skip to content

Instantly share code, notes, and snippets.

@webdesignberlin
Created January 2, 2018 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdesignberlin/00caf418549efa7f001c94357402e270 to your computer and use it in GitHub Desktop.
Save webdesignberlin/00caf418549efa7f001c94357402e270 to your computer and use it in GitHub Desktop.
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