Hay que usar javascript, pero es un poco exagerado usar una librería. Probemos con javascript nativo
Código HTML:
Ver original<!DOCTYPE html>
<html dir="ltr" lang="es-es"> <meta name="viewport" content="user-scalable=yes, width=device-width, initial-scale=1"> * {
margin: 0;
border: none;
position: relative;
}
html {
height: 100%;
}
body {
width: 100%;
height: 100%;
}
#container {
height: 1000px;
}
.header {
display: -webkit-flex;
display: flex;
}
.logo {
width: 200px;
background: red;
}
.flex-column {
-webkit-flex: 1;
flex: 1;
background: yellow;
}
section {
background: pink;
}
section ul {
list-style: none;
margin: 0;
}
.ocultar {
height: 0;
}
function fijar(obj) {
this.header = obj.header;
this.ocultar = obj.ocultar;
this.ocultarHeight = obj.ocultar === null ? 0 : obj.ocultar.offsetHeight;
this.posElem = (obj.header.offsetTop + this.ocultarHeight)
this.flag = true;
var _this = this;
window.addEventListener('scroll', function() { _this.scroll() });
}
fijar.prototype.scroll = function() {
var scrollVertical = window.pageYOffset;
if (scrollVertical >= this.posElem && this.flag) {
this.header.style.position = 'fixed';
//this.header.style.top = -this.ocultarHeight + 'px';
//this.ocultar.style.display = 'none';
this.ocultar.classList.toggle('ocultar');
this.flag = false;
} else if (scrollVertical < this.posElem && !this.flag) {
this.header.style.position = 'static';
//this.header.style.top = 0;
//this.ocultar.style.display = 'block';
this.ocultar.classList.toggle('ocultar');
this.flag = true;
}
}
document.addEventListener('DOMContentLoaded', function() {
new fijar({
header : document.querySelector('div.header'),
ocultar : document.querySelector('#ocultar') // o null
})
});
<div class="flex-column">