Giter VIP home page Giter VIP logo

simple-sticky-header's Introduction

simple-sticky-header

Very simple javascript & CSS fixed header on scroll down based on an element's height (IE 6+ minimum): CodePen demo.

Pure vanilla javascript with no dependencies. Add a "fixed" class on an identified div element (#header) which allow to fix it when visitors scroll down on a web page. Calculations are made automaticaly based on the height of this #header. Simply copy/past: you just need to add a CSS declaration into your styles file (i.e.: .fixed{position:fixed}).

HTML markup

<div class="header-outer" id="header-outer">
  <div class="header-inner" id="header">
    Header
  </div>
</div>

Note: IDs header-outer & header are needed (can be changed for other identifiants, see options below).

Options

down: distance in pixels from the top of the page where to apply the fixed element. Default: the #header's height.

up: distance in pixels from the top of the page where to stop the fixed element. Default: the #header's height.

delay: timeout in milliseconds. Default: 70.

Script loader

Call this script with its function fixednav() and set options as needed:

fixednav({id:"inner-id", outer:"outer-id", distance:40, down:50, up:200, delay:70});

Attributes

id: ID of the inner element of the header.

outer: ID of the outer element of the header.

distance: (optional) distance in pixel from the top of the browser's window where to apply the fixed position. Default: the menu element height.

down: (optional) additional down distance in pixel when to apply the fixed position. Default: 0.

up: (optional) additional up distance in pixel when to remove the fixed position. Default: 0.

delay: (optional) delay in ms. Default: 70 ms.

Check out: this online demo (new version).

Check out: this online demo (old version).

simple-sticky-header's People

Contributors

cara-tm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.