Only scroll sidebar item into view if needed [ci skip]

This commit is contained in:
ines 2018-06-12 10:58:50 +02:00
parent 65713a6593
commit 53a2bc8c8d
2 changed files with 6 additions and 6 deletions

View File

@ -84,8 +84,8 @@
}
],
"V_CSS": "2.2.0",
"V_JS": "2.2.0",
"V_CSS": "2.2.1",
"V_JS": "2.2.1",
"DEFAULT_SYNTAX": "python",
"ANALYTICS": "UA-58931649-1",
"MAILCHIMP": {

View File

@ -61,10 +61,10 @@ import initUniverse from './universe.vue.js';
const sidebarAttr = 'data-sidebar-active';
const sections = [...document.querySelectorAll(`[${navAttr}]`)];
const currentItem = document.querySelector(`[${sidebarAttr}]`);
if (currentItem && Element.prototype.scrollIntoView) {
currentItem.scrollIntoView();
}
if (window.inView) {
if (currentItem && Element.prototype.scrollIntoView && !inView.is(currentItem)) {
currentItem.scrollIntoView();
}
if (sections.length) { // highlight first item regardless
sections[0].classList.add(activeClass);
}
@ -74,7 +74,7 @@ import initUniverse from './universe.vue.js';
if (el) {
sections.forEach(el => el.classList.remove(activeClass));
el.classList.add(activeClass);
if (Element.prototype.scrollIntoView) {
if (Element.prototype.scrollIntoView && !inView.is(el)) {
el.scrollIntoView();
}
}