Skip to content

Commit 65c4461

Browse files
authored
resolves #55 make vh unit adjustable using --vh property (PR #56)
1 parent fe1047a commit 65c4461

File tree

8 files changed

+49
-25
lines changed

8 files changed

+49
-25
lines changed

gulp.d/tasks/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = (src, dest, preview) => () => {
5353
},
5454
]),
5555
// NOTE importFrom is for supplemental CSS files
56-
postcssVar({ importFrom: path.join(src, 'css', 'vars.css'), preserve: preview }),
56+
postcssVar({ importFrom: path.join(src, 'css', 'vars.css'), preserve: true }),
5757
preview ? postcssCalc : () => {},
5858
autoprefixer,
5959
preview

src/css/base.css

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
html,
2-
body {
3-
height: 100%;
4-
}
5-
61
*,
72
*::before,
83
*::after {
@@ -12,6 +7,8 @@ body {
127
html {
138
box-sizing: border-box;
149
font-size: var(--body-font-size);
10+
height: var(--viewport-height);
11+
min-height: 100vh; /* used as a reference to detect invalid vh unit */
1512
}
1613

1714
@media screen and (min-width: 1024px) {

src/css/header.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ html.is-clipped--navbar {
22
overflow-y: hidden;
33
}
44

5+
/* NOTE workaround bug in Firefox mobile, which clips the html element to the original viewport height */
6+
@supports (scrollbar-width: none) {
7+
html.is-clipped--navbar {
8+
overflow-y: initial;
9+
scrollbar-width: none;
10+
}
11+
}
12+
513
body {
614
padding-top: var(--navbar-height);
715
}
@@ -251,7 +259,7 @@ body {
251259
.navbar-menu.is-active {
252260
display: block;
253261
box-shadow: 0 8px 16px rgba(10, 10, 10, 0.1);
254-
max-height: calc(100vh - var(--navbar-height));
262+
max-height: calc(var(--viewport-height) - var(--navbar-height));
255263
overflow-y: auto;
256264
}
257265

src/css/nav.css

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
@media screen and (max-width: 769.5px) {
2+
html.is-clipped--nav {
3+
overflow-y: hidden;
4+
}
5+
6+
/* NOTE workaround bug in Firefox mobile, which clips the html element to the original viewport height */
7+
@supports (scrollbar-width: none) {
8+
html.is-clipped--nav {
9+
overflow-y: initial;
10+
scrollbar-width: none;
11+
}
12+
}
13+
}
14+
115
.nav-container {
216
position: fixed;
317
top: var(--navbar-height);
@@ -56,10 +70,6 @@
5670
height: inherit;
5771
}
5872

59-
html.is-clipped--nav {
60-
overflow-y: hidden;
61-
}
62-
6373
.nav-panel-menu {
6474
overflow-y: scroll;
6575
display: flex;

src/css/vars.css

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
--color-jet-70: #222;
1919
--color-jet-80: #191919;
2020
--color-black: #000;
21-
/* fonts */
21+
/* utils */
2222
--rem-base: 18; /* used to compute rem value from desired pixel value (e.g., calc(18 / var(--rem-base) * 1rem) = 18px) */
23+
--viewport-height: calc(100 * var(--vh, 1vh)); /* used to represent a tunable value of 100vh */
24+
/* fonts */
2325
--body-font-size: 1.0625em; /* 17px */
2426
--body-font-size--desktop: 1.125em; /* 18px */
2527
--body-font-size--print: 0.9375em; /* 15px */
@@ -126,14 +128,14 @@
126128
--toolbar-height: calc(45 / var(--rem-base) * 1rem);
127129
--drawer-height: var(--toolbar-height);
128130
--body-top: var(--navbar-height);
129-
--body-min-height: calc(100vh - var(--body-top));
131+
--body-min-height: calc(var(--viewport-height) - var(--body-top));
130132
--nav-height: calc(var(--body-min-height) - var(--toolbar-height));
131133
--nav-height--desktop: var(--body-min-height);
132134
--nav-panel-height: calc(var(--nav-height) - var(--drawer-height));
133135
--nav-panel-height--desktop: calc(var(--nav-height--desktop) - var(--drawer-height));
134136
--nav-width: calc(270 / var(--rem-base) * 1rem);
135137
--toc-top: calc(var(--body-top) + var(--toolbar-height));
136-
--toc-height: calc(100vh - var(--toc-top) - 2.5rem);
138+
--toc-height: calc(var(--viewport-height) - var(--toc-top) - 2.5rem);
137139
--toc-width: calc(162 / var(--rem-base) * 1rem);
138140
--toc-width--widescreen: calc(216 / var(--rem-base) * 1rem);
139141
--doc-max-width: calc(720 / var(--rem-base) * 1rem);

src/css/vendor/docsearch.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@import "docsearch.js/dist/cdn/docsearch.css";
22

33
.algolia-autocomplete .ds-dropdown-menu > :first-child {
4-
max-height: calc(100vh - var(--navbar-height));
4+
max-height: calc(var(--viewport-height) - var(--navbar-height));
55
}
66

77
.algolia-autocomplete .algolia-docsearch-suggestion--title {

src/js/01-nav.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,16 @@
107107
if (navToggle.classList.contains('is-active')) return hideNav(e)
108108
trapEvent(e)
109109
var html = document.documentElement
110+
if (/mobi/i.test(window.navigator.userAgent)) {
111+
if (Math.round(parseFloat(window.getComputedStyle(html).minHeight)) !== window.innerHeight) {
112+
html.style.setProperty('--vh', window.innerHeight / 100 + 'px')
113+
} else {
114+
html.style.removeProperty('--vh')
115+
}
116+
}
110117
html.classList.add('is-clipped--nav')
111118
navToggle.classList.add('is-active')
112119
navContainer.classList.add('is-active')
113-
var bounds = nav.getBoundingClientRect()
114-
var expectedHeight = window.innerHeight - Math.round(bounds.top)
115-
if (Math.round(bounds.height) !== expectedHeight) nav.style.height = expectedHeight + 'px'
116120
html.addEventListener('click', hideNav)
117121
}
118122

src/js/05-mobile-navbar.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
function toggleNavbarMenu (e) {
99
e.stopPropagation() // trap event
10-
document.documentElement.classList.toggle('is-clipped--navbar')
11-
this.classList.toggle('is-active')
10+
var html = document.documentElement
1211
var menu = document.getElementById(this.dataset.target)
13-
if (menu.classList.toggle('is-active')) {
14-
menu.style.maxHeight = ''
15-
var expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top)
16-
var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10)
17-
if (actualMaxHeight !== expectedMaxHeight) menu.style.maxHeight = expectedMaxHeight + 'px'
12+
if (!menu.classList.contains('is-active') && /mobi/i.test(window.navigator.userAgent)) {
13+
if (Math.round(parseFloat(window.getComputedStyle(html).minHeight)) !== window.innerHeight) {
14+
html.style.setProperty('--vh', window.innerHeight / 100 + 'px')
15+
} else {
16+
html.style.removeProperty('--vh')
17+
}
1818
}
19+
html.classList.toggle('is-clipped--navbar')
20+
this.classList.toggle('is-active')
21+
menu.classList.toggle('is-active')
1922
}
2023
})()

0 commit comments

Comments
 (0)