Code Monkey home page Code Monkey logo

headhesive.js's Introduction

Headhesive.js

An on-demand sticky header.

What is it?

Headhesive.js creates an on-demand sticky header. Specify when you want your header to become fixed and the rest is magic. View demo.

Bower

Install Headhesive.js with Bower:

$ bower install headhesive.js

How to use?

Headhesive.js is a standalone JavaScript plugin with no dependancies. Include the headhesive.min.js (from the dist/ folder) in the footer of your page and initialise it:

// Create a new instance of Headhesive
var headhesive = new Headhesive('.header');

Styling Headhesive.js

Headhesive.js doesn't inject any CSS styles so you can use your own to completely control how your sticky element behaves. An example is provided in the demo.

Options

Customise how Headhesive works by passing in custom options.

// Options
var options = {
    offset: 500
}

// Create a new instance of Headhesive and pass in some options
var header = new Headhesive('.header', options);

Defaults

{
    // Scroll offset. Accepts Number or "String" (for class/ID)
    offset: 300, // OR โ€” offset: '.classToActivateAt',

    // Custom classes
    classes: {

        // Cloned elem class
        clone: 'headhesive',

        // Stick class
        stick: 'headhesive--stick',

        // Unstick class
        unstick: 'headhesive--unstick'
    },

    // Throttle scroll event to fire every 250ms to improve performace
    throttle: 250,

    // Callbacks
    onInit: function() {},
    onStick: function() {},
    onUnstick: function() {},
    onDestroy: function() {},
}

Destroy method

To destroy an instance of Headhesive.js, you can call the destroy method:

header.destroy();

Browser support

IE9+ and modern browsers.

License

Headesive.js is licensed under the MIT License.

Demo

There is a demo available in the demo folder and online at http://markgoodyear.com/labs/headhesive/.

headhesive.js's People

Contributors

markgoodyear avatar

Watchers

John Wallace avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.