Download
User Rating: 4.1/5 ( 2 votes)
Headhesive.js creates an on-demand sticky header. Specify when you want your header to become fixed and the rest is magic.
Source: github.com
1. INCLUDE CSS AND JS FILES
<link rel="stylesheet" href="/labs/headhesive/css/headhesive.css">
<script type="text/javascript" src="/labs/headhesive/js/headhesive.min.js"></script>
2. HTML
<header class="banner">
<nav class="container">
<h1 class="logo">Headhesive.js</h1>
<ul class="nav">
<li class="nav__item"><a href="https://twitter.com/markgdyr">@markgdyr</a></li>
<!-- <li class="nav__item"><a class="nav__item--btn btn" href="http://markgoodyear.com/blog">View Article →</a></li> -->
</ul>
</nav>
</header>
3. JAVASCRIPT
// Set options
var options = {
offset: '#showHere',
classes: {
clone: 'banner--clone',
stick: 'banner--stick',
unstick: 'banner--unstick'
}
};
// Initialise with options
var banner = new Headhesive('.banner', options);
4. OPTIONS
{
// 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() {},
}
5. DESTROY METHOD
To destroy an instance of Headhesive.js, you can call the destroy method: