Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Update doc navigation

Julian Garnier055502d11760
diff --git a/documentation/assets/css/styles.css b/documentation/assets/css/styles.css
index f5fa7353..7f7bed46 100644
--- a/documentation/assets/css/styles.css
+++ b/documentation/assets/css/styles.css
@@ -108,11 +108,13 @@ h2,
}
.navigation ul {
+ height: 20px;
margin-bottom: 10px;
+ overflow-y: hidden;
+ transition: opacity .4s ease;
}
.navigation a {
- opacity: .6;
display: block;
padding-left: 10px;
color: #FFF;
@@ -126,17 +128,32 @@ h2,
background-position: 0 4px;
}
-.navigation li:first-child a {
+.navigation ul li:first-child a {
padding-left: 0;
background-image: none;
}
-.navigation a:hover {
- color: currentColor;
+.navigation ul a {
+ opacity: .4;
+ transition: opacity .4s ease, color .4s ease;
+}
+
+.navigation ul.active a {
+ opacity: .7;
}
-.navigation a.active {
+.navigation ul a:hover {
+ transition: none;
opacity: 1;
+}
+
+.navigation ul a.active {
+ opacity: 1;
+ color: currentColor;
+}
+
+.navigation ul.active li:first-child a,
+.navigation ul.active li:first-child a:hover {
color: currentColor;
}
diff --git a/documentation/assets/js/scripts.js b/documentation/assets/js/scripts.js
index c1839095..c6c6b84b 100644
--- a/documentation/assets/js/scripts.js
+++ b/documentation/assets/js/scripts.js
@@ -48,6 +48,29 @@ function outputCode(JScode, HTMLcode) {
hljs.highlightBlock(htmlOutputEl);
}
+function toggleSectionLink(ulEl) {
+ var ulHeight = 20;
+ var ulEls = document.querySelectorAll('.navigation ul');
+ for (var i = 0; i < ulEls.length; i++) ulEls[i].classList.remove('active');
+ anime({
+ targets: '.navigation ul',
+ height: ulHeight,
+ duration: 400,
+ easing: 'easeOutQuart'
+ });
+ anime.remove(ulEl);
+ anime({
+ targets: ulEl,
+ height: function(el) {
+ return el.childNodes.length * ulHeight;
+ },
+ duration: 600,
+ delay: 400,
+ easing: 'easeInOutQuart'
+ });
+ ulEl.classList.add('active');
+}
+
function createDemo(el) {
var demo = {};
var scriptEl = el.querySelector('script');
@@ -70,9 +93,11 @@ function createDemo(el) {
history.pushState(null, null, '#'+id);
outputCode(JScode, HTMLcode);
var linkEl = document.querySelector('a[href="#'+id+'"]');
+ var ulEl = linkEl.parentNode.parentNode;
linkEl.classList.add('active');
el.classList.add('active');
scrollTo('#'+id, 60);
+ toggleSectionLink(ulEl);
}
if (!el.classList.contains('controls')) demoAnim.restart();
}
@@ -100,6 +125,10 @@ function createDemo(el) {
}
}
+function getDemoById(id) {
+ return demos.filter(function(a) { return a.id === id})[0];
+}
+
function createLinksSection(articleEl) {
var articleId = articleEl.id;
var articleTitle = articleEl.querySelector('h2').innerHTML;
@@ -109,6 +138,12 @@ function createLinksSection(articleEl) {
var sectionLinkEl = document.createElement('a');
sectionLinkEl.setAttribute('href', '#'+articleId);
sectionLinkEl.innerHTML = articleTitle;
+ sectionLinkEl.addEventListener('click', function(e) {
+ e.preventDefault();
+ var firstDemoId = articleEl.querySelector('.demo').id;
+ var firstDemo = getDemoById(firstDemoId);
+ firstDemo.highlight();
+ });
liEl.appendChild(sectionLinkEl);
ulEl.appendChild(liEl);
ulEl.classList.add(colorClass);
@@ -145,7 +180,7 @@ navigationEl.appendChild(fragment);
var hash = window.location.hash;
if (hash) {
var id = hash.replace('#','');
- var demo = demos.filter(function(a) { return a.id === id})[0];
+ var demo = getDemoById(id);
if (demo) demo.highlight();
} else {
demos[0].highlight();