Created
June 25, 2014 15:36
-
-
Save felixzapata/83a621322ce67e1acdde to your computer and use it in GitHub Desktop.
handle the swanky navigation/section stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://speckyboy.com/2014/06/25/content-overlays-css3-transitions/ | |
(function(){ | |
// handle the swanky navigation/section stuff | |
//////////////////////////////////////////////////////////// | |
var nav_links = document.querySelectorAll("nav.cmn-overlays-nav a"); | |
/* loop through all nav links */ | |
[].slice.call(nav_links).forEach(function(el, i) { | |
/* fetch vars */ | |
var href = el.getAttribute("href"), | |
id = href.substr(1), | |
section = document.querySelector(href), | |
close = section.querySelector("a.close"); | |
/* listen for nav clicks */ | |
el.addEventListener("click", function(e) { | |
e.preventDefault(); | |
if (!classie.has(section, "active")) { | |
classie.add(section, "active"); | |
} | |
}); | |
/* listen for close clicks on the mask */ | |
section.addEventListener("click", function(e) { | |
e.preventDefault(); | |
if (e.target.tagName == "SECTION") { | |
if (classie.has(section, "active")) { | |
classie.remove(section, "active"); | |
} | |
} | |
}); | |
/* listen for close clicks on the close button */ | |
close.addEventListener("click", function(e) { | |
e.preventDefault(); | |
if (classie.has(section, "active")) { | |
classie.remove(section, "active"); | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment