Skip to content

An affixing header that behaves normally as a user navigates down a page, but reveals itself naturally when a user scrolls or drags upwards. Inspired by iOS Safari, Medium, and others.

master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Affixing Header  Build Status

Create an affixing header that behaves normally as a user navigates down a page, but reveals itself naturally when a user scrolls or drags upwards. Inspired by iOS Safari, Medium, and others. See an example implementation to see what it’s about. Works on desktop and mobile browsers.

Sauce Test Status

Usage

The module itself is available in a wide range of flavors:

  1. As a CommonJS (Browserify-friendly) module (via UMD): dist/affixing-header.js
  2. As an AMD (RequireJS-friendly) module (also via UMD): dist/affixing-header.js
  3. As the window.affixingHeader global with dependencies bundled in: dist/affixing-header-bundled.js, or minified as dist/affixing-header-bundled-min.js
  4. As an ES6/ES2015 module (identified by jsnext:main in package.json), compatible with ES6-compatible module loaders like SystemJS or compilers like Babel: src/affixing-header.js

Exports a single function via require('affixing-header') if being used with a CommonJS or AMD module loader, or else exposes the function as a global named window.affixingHeader.

affixingHeader( element )

element Element

The DOM element to which the affixing behavior should be attached. Must be a single Element (e.g., the result of document.querySelector or document.getElementById), not a NodeList.

Dependencies

This package uses onscrolling, a requestAnimationFrame-based, performant, mobile-friendly scroll event handler, to listen for page scrolls, but has no other dependencies.

Compatibility

The scroll handling uses requestAnimationFrame, which is only available in IE10+. For older browsers, your header won’t affix to the top of the page when you scroll up, but you shouldn’t see any other issues (yay progressive enhancement). To add full support for older browsers, just include a requestAnimationFrame polyfill.

About

An affixing header that behaves normally as a user navigates down a page, but reveals itself naturally when a user scrolls or drags upwards. Inspired by iOS Safari, Medium, and others.

Resources

License

Packages

No packages published