Skip to content

Commit

Permalink
fix: optimize header-inner's display experience
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Mar 5, 2020
1 parent de4def3 commit fd95216
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
18 changes: 8 additions & 10 deletions assets/js/header.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// Header Inner Width

{{ with .Site.Params.headerFallbackWidth | default "32em" }}
const headerFallbackWidth = '{{ . }}';
{{ end }}

const headerInner = document.querySelector('.header-inner');
const mainInner = document.querySelector('.main-inner');

function setHeaderInnerWidth() {
if (mainInner !== null) {
const mainInnerWidth = window.getComputedStyle(mainInner, null).getPropertyValue('width');

headerInner.style.setProperty('--main-inner', mainInnerWidth);
}

if (mainInner !== null) {
setHeaderInnerWidth();

window.addEventListener('resize', setHeaderInnerWidth);
} else {
{{ with .Site.Params.headerFallbackWidth | default "32em" }}
headerInner.style.setProperty('--main-inner', '{{ . }}');
{{ end }}
headerInner.style.setProperty('--main-inner', headerFallbackWidth);
}

headerInner.style.setProperty('opacity', 1);


// Hide switcher's parentNode if it has `data-hide`

Expand Down
1 change: 1 addition & 0 deletions assets/scss/layout/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
background: $headerBackground;
}
.header-inner {
opacity: 0;
display: flex;
justify-content: space-between;
align-items: center;
Expand Down
Loading

0 comments on commit fd95216

Please sign in to comment.