Toggles header visibility on scroll. Demo.
Installation
npm install hiding-header
How to use
HTML:
<body>
<div class="hidingHeader" id="hidingHeader">
<div class="hidingHeader-in">
</div>
</div>
</body>
CSS:
.hidingHeader {
position: relative;
--hidingHeader-height: auto;
--hidingHeader-bounds-height: auto;
z-index: 10;
height: var(--hidingHeader-bounds-height);
margin-bottom: calc(
var(--hidingHeader-height) - var(--hidingHeader-bounds-height)
);
pointer-events: none;
}
.hidingHeader-in {
position: relative;
position: sticky;
top: 0;
pointer-events: auto;
}
JavaScript:
import { hidingHeader } from 'hiding-header'
const container = document.querySelector('#hidingHeader')
hidingHeader(container)
React component (HTML alternative)
import React, { useEffect } from 'react'
import { hidingHeader } from 'hiding-header'
export const HidingHeader = (props) => {
const container = React.useRef()
useEffect(() => {
hidingHeader(container.current)
}, [])
return (
<div className="hidingHeader" ref={container}>
<div className="hidingHeader-in">{props.children}</div>
</div>
)
}