headroom.js

Give your pages some headroom. Hide your header until you need it

  • 所有者: WickyNilliams/headroom.js
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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:

https://unpkg.com/headroom.js

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:

  1. Fork the repo (click the Fork button at the top right of this page)
  2. Clone your fork locally
git clone https://github.com/<your_github_username>/headroom.js.git
cd headroom.js
  1. 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.

概览

名称与所有者WickyNilliams/headroom.js
主编程语言JavaScript
编程语言JavaScript (语言数: 2)
平台
许可证MIT License
发布数28
最新版本名称v0.12.0 (发布于 2020-10-16 14:08:56)
第一版名称v0.3.9 (发布于 2013-09-15 20:37:29)
创建于2013-08-07 20:42:58
推送于2023-10-25 11:50:31
最后一次提交2020-10-16 14:08:56
星数10.9k
关注者数193
派生数830
提交数218
已启用问题?
问题数291
打开的问题数13
拉请求数51
打开的拉请求数7
关闭的拉请求数41
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?
去到顶部