1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-09-24 11:28:23 +02:00

Refactored wrapper structure to allow variable-sized sticky footer

This commit is contained in:
squidfunk 2016-12-26 14:31:16 +01:00
parent de177ca0c5
commit 5000e3ee8d
11 changed files with 53 additions and 39 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono:400"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono:400">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-e74c14d4c7.css"> <link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-ca351710b4.css">
{% if config.extra.palette %} {% if config.extra.palette %}
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-535e87ca3f.palette.css"> <link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-535e87ca3f.palette.css">
{% endif %} {% endif %}
@ -124,7 +124,7 @@
<script src="https://cdn.mathjax.org/{{ path }}"></script> <script src="https://cdn.mathjax.org/{{ path }}"></script>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<script src="{{ base_url }}/assets/javascripts/application-d61fcbb674.js"></script> <script src="{{ base_url }}/assets/javascripts/application-e2d270ac30.js"></script>
<script> <script>
/* Configuration for application */ /* Configuration for application */
var config = { var config = {

View File

@ -95,10 +95,11 @@ export default class Application {
} }
/* Component: sidebar container */ /* Component: sidebar container */
new Material.Event.MatchMedia("(min-width: 960px)", if (!Modernizr.csscalc)
new Material.Event.Listener(window, [ new Material.Event.MatchMedia("(min-width: 960px)",
"resize", "orientationchange" new Material.Event.Listener(window, [
], new Material.Sidebar.Container("[data-md-container]"))) "resize", "orientationchange"
], new Material.Sidebar.Container("[data-md-container]")))
/* Component: sidebar with navigation */ /* Component: sidebar with navigation */
new Material.Event.MatchMedia("(min-width: 1200px)", new Material.Event.MatchMedia("(min-width: 1200px)",

View File

@ -52,11 +52,8 @@ export default class Container {
* Update minimum height * Update minimum height
*/ */
update() { update() {
const height = window.innerHeight - this.parent_.offsetTop const height = this.parent_.offsetHeight - this.el_.offsetTop
const margin = this.parent_.offsetHeight - this.el_.offsetHeight this.el_.style.minHeight = `${height}px`
/* Set new minimum height */
this.el_.style.minHeight = `${height - margin}px`
} }
/** /**

View File

@ -37,12 +37,9 @@ export default class Position {
? document.querySelector(el) ? document.querySelector(el)
: el : el
/* Retrieve inner and outer container */ /* Initialize parent container, top offset and current height */
this.inner_ = this.el_.parentNode this.parent_ = this.el_.parentNode
this.outer_ = this.el_.parentNode.parentNode this.offset_ = this.el_.offsetTop - this.parent_.offsetTop
/* Initialize top offset and current height */
this.offset_ = this.outer_.offsetTop
this.height_ = 0 this.height_ = 0
} }
@ -55,29 +52,35 @@ export default class Position {
/** /**
* Update locked state and height * Update locked state and height
*
* The inner height of the window (= the visible area) is the maximum
* possible height for the stretching sidebar. This height must be deducted
* by the top offset of the parent container, which accounts for the fixed
* header, setting the baseline. Depending on the page y-offset, the top
* offset of the sidebar must be taken into account, as well as the case
* where the window is scrolled beyond the sidebar container.
*/ */
update() { update() {
const scroll = window.pageYOffset const offset = window.pageYOffset
const expand = window.innerHeight const visible = window.innerHeight
/* Calculate bounds of sidebar container */ /* Calculate bounds of sidebar container */
this.bounds_ = { this.bounds_ = {
top: this.inner_.offsetTop, top: this.parent_.offsetTop,
bottom: this.inner_.offsetTop + this.inner_.offsetHeight bottom: this.parent_.offsetTop + this.parent_.offsetHeight
} }
/* Calculate new offset and height */ /* Calculate new offset and height */
const offset = this.bounds_.top - scroll const height = visible - this.bounds_.top
const height = expand - Math.max(0, this.offset_ - offset)
- Math.max(0, scroll + expand - this.bounds_.bottom) - Math.max(0, offset + visible - this.bounds_.bottom)
- Math.max(offset, this.offset_)
/* If height changed, update element */ /* If height changed, update element */
if (height !== this.height_) if (height !== this.height_)
this.el_.style.height = `${this.height_ = height}px` this.el_.style.height = `${this.height_ = height}px`
/* Sidebar should be locked, as we're below parent offset */ /* Sidebar should be locked, as we're below parent offset */
if (offset < this.offset_) { if (offset >= this.offset_) {
if (this.el_.dataset.mdState !== "lock") if (this.el_.dataset.mdState !== "lock")
this.el_.dataset.mdState = "lock" this.el_.dataset.mdState = "lock"

View File

@ -44,7 +44,7 @@ html {
// Stretch body to container and leave room for footer. // Stretch body to container and leave room for footer.
body { body {
position: relative; position: relative;
min-height: 100%; height: 100%;
// [tablet portrait -]: Lock body to disable scroll bubbling // [tablet portrait -]: Lock body to disable scroll bubbling
@include break-to-device(tablet portrait) { @include break-to-device(tablet portrait) {
@ -78,15 +78,30 @@ hr {
overflow: auto; overflow: auto;
} }
// Add top spacing to acount for header // Content wrapper - use display: table for to make variable-sized sticky
.md-main { // footers work and fixed table-layout for IE
margin-top: 5.6rem; .md-container {
display: table;
width: 100%;
height: 100%;
table-layout: fixed;
}
// Bottom spacing to account for header and footer // The main content should stretch to maximum height in the table
.md-main {
display: table-row;
height: 100%;
// Top-spacing to account for header and some additional padding
&__inner { &__inner {
margin-top: 2.4rem + 0.6rem; margin-top: 5.6rem;
margin-bottom: 9.2rem; padding-top: 2.4rem + 0.6rem;
overflow: auto; overflow: auto;
// If the browser supports calc(), no JavaScript is necessary
.csscalc & {
min-height: calc(100% - #{5.6rem - 3.0rem});
}
} }
} }

View File

@ -26,8 +26,6 @@
// Application footer // Application footer
.md-footer { .md-footer {
position: absolute;
bottom: 0;
width: 100%; width: 100%;
// Hide for print // Hide for print