Git Product home page Git Product logo

sticky-header-1's Introduction

Sticky Header

Simple jQuery plugin for making sticky header.
Complete Guide and Demo

Wordpress Version: https://wordpress.org/plugins/advanced-sticky-header/

HTML

<script type="text/javascript" src="js/jquery.min.js"></script> 
<script type="text/javascript" src="js/sticky-header.js"></script>

<header class="example"> <!-- header stuff ... --> </header>



Call the plugin

$(document).ready(function(){
  $('.example').stickMe(); 
})



Plugin classes

<!-- Now plugin adds classes to your header on page load --> 
<header class="example stick-me not-sticking"> 
  <!--  header stuff ... --> 
</header>

<!-- Header is sticky --> <header class="example stick-me sticking"> <!-- header stuff ... --> </header>



Something about styles


/* Make sure your header has z-index and background set and it's also full width */
.example {
  width: 100%;
  z-index: 999;
  background-color: #ffffff;
}

/* OR you can also style plugin's class .sticking, that way you can style it differently when it's sticking */ .sticking { width: 100%; z-index: 999; background-color: #ffffff; }



Defaults

transitionDuration: 300,
shadow: false,
shadowOpacity: 0.3,
animate: true,
triggerAtCenter: true,
transitionStyle: 'fade',
stickyAlready: false



Customizing

Variable Type Example Description
topOffset int
topOffset: 300
Header will become sticky when the body is scrolled down by 300 pixels
shadow boolean
shadow: true
Header will have shadow when it becomes sticky
shadowOpacity float
shadowOpacity: 0.5
This sets the opacity of shadow that header gets when it's sticky
animate boolean
animate: true
This brings header into display smoothly
transitionStyle string
transitionStyle: 'fade'
Transition style for header when it becomes sticky
'fade'
'slide'
triggetAtCenter boolean
triggerAtCenter: false
By default header becomes sticky when it reaches the center of viewport, setting it to false will make header sticky just when header is scrolled out of the viewport
stickyAlready boolean
stickyAlready: true
Makes header sticky when page loads
transitionDuration int
transitionDuration: 1000
Transition duration of animation


Events

Event Description
sticky-begin When header gets sticky
sticking When header is sticking (This event is called every time page is scrolled and header is sticky)
top-reached When document's top is reached
bottom-reached When document's bottom is reached



Using Events

$(document).ready(function(){
  $('.site-header').on('sticky-begin', function() { 
    console.log("Began"); 
  });

$('.site-header').on('sticking', function() { console.log("Sticking"); });

$('.site-header').on('top-reached', function() { console.log("Top reached"); });

$('.site-header').on('bottom-reached', function() { console.log("Bottom reached"); }); })

sticky-header-1's People

Contributors

m-danish-iqbal avatar

Watchers

 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.