Git Product home page Git Product logo

sticky-nav's Introduction

#stickyNav.js stickyNavbar.js: A jQuery plugin make the navbar sticky, smart anchor link highlighting, smooth scrolling. Simple and powerful.

##1. Setup Include jQuery library and stickyNav.js itself:

install by bower:

bower install sticky-nav
<!-- all these references goes before the closing body tag-->
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="/script/stickyNav.js"></script>

##2. HTML Markup

Navigation:

<div class="header">header</div>
<div class="banner">banner</div>
<div class="nav">
    <ul>
        <li>
            <div><a href="#we">we</a></div>
        </li>
        <li>
            <div><a href="#should">should</a></div>
        </li>
        <li>
            <div><a href="#make">make</a></div>
        </li>
        <li>
            <div><a href="#life">life</a></div>
        </li>
        <li>
            <div><a href="#easier">easier</a></div>
        </li>
    </ul>
</div>

Body markup, not require any addtional class name:

<div id="we">
		<!-- Your content goes here -->
</div>
<div id="should">
		<!-- Your content goes here -->
</div>
<div id="make">
		<!-- Your content goes here -->
</div>
<div id="life">
		<!-- Your content goes here -->
</div>
<div id="easier">
		<!-- Your content goes here -->
</div>

##3. CSS: Add active class into your style.css and style it as you like, eg.:

ul.active a {
  color: #fff !important;
}

Note: You can attch active class to li in navbar or the a in navbar directly, check the options object usage below.

##4. jQuery: Call stickyNavbar function on the navigation wrapper (.header), nav tag or ul tag either without options object:

$('.nav').stickyNavbar();

or with the options object:

var options = {
  header: '.header', //the header selector
  activeClass: "active", // the class you want to attach
  attachActiveClassTo: "li", // the element you want to attach active class "li"/"a"
  animationDuration: 500, // the animation duration for smooth scroll
  easing: "swing", // the animation easing for smooth scroll
  disableOnMobile: true, // if disable sticky nav on mobile
  mobileWidth: 480 // default break point for mobile width
};

$('.nav').stickyNavbar(options);

##5. Demo http://chenzhihao.github.io/sticky-Nav/

##Contact Copyright (C) 2014 Zhihao Chen
@Linkedin
[email protected]

sticky-nav's People

Contributors

chenzhihao avatar

Watchers

Jing Liu  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.