Headroom.js
Give your pages some headroom. Hide your header until you need it
Install / Use
/learn @WickyNilliams/Headroom.jsREADME
Headroom.js
Headroom.js is a lightweight, high-performance JS widget (with no dependencies) that allows you to react to the user's scroll. The header on this site is a living example, it slides out of view when scrolling down and slides back in when scrolling up.
Installation
Headroom.js is available on npm. To install:
npm install headroom.js --save
# or...
yarn add headroom.js
A a universal build (suitable for script tags, CommonJS, and AMD) is available from unpkg.com:
Documentation
For complete documentation please visit the headroom.js website.
Quick start
After installing headroom.js. The following JS will create and initialise a headroom instance:
import Headroom from "headroom.js";
// select your header or whatever element you wish
const header = document.querySelector("header");
const headroom = new Headroom(header);
headroom.init();
Then you can add the following CSS to your page:
.headroom {
will-change: transform;
transition: transform 200ms linear;
}
.headroom--pinned {
transform: translateY(0%);
}
.headroom--unpinned {
transform: translateY(-100%);
}
You should now see your header slide in and out in response to the user's scroll.
Contributions & Issues
Contributions are welcome. Please clearly explain the purpose of the PR and follow the current code style.
Issues can be resolved quickest if they are descriptive and include both a reduced test case and a set of steps to reproduce.
Contributing Guide
Setup
The following steps will get you setup to contribute changes to this repo:
- Fork the repo (click the <kbd>Fork</kbd> button at the top right of this page)
- Clone your fork locally
git clone https://github.com/<your_github_username>/headroom.js.git
cd headroom.js
- Install dependencies. This repo uses
npm, so you should too.
npm install
Building
To build the project:
npm run build
To start a watcher for building the project and running tests:
npm start
Testing
To run the test suite in headless mode:
npm test
License
Licensed under the MIT License.
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
