The hideHeaderOnScroll jQuery plugin
The hideHeaderOnScroll is a jQuery plugin that hides the page header when the user scrolls down the page, and shows the header when the user scrolls up the page.
* Scroll down and up the page to see the hideHeaderOnScroll plugin in action
The hideHeaderOnScroll plugin allows for part of the header to remain visible when you scroll the page down, and ofcourse you can choose to hide all of the header when you scroll down the page.
You can learn how to install the plugin in the installation section, and about how to customize the plugin in the settings section.
# Usage
The hideHeaderOnScroll plugin needs a fixed header object on which it can perform its tricks.
$("#header").hideHeaderOnScroll();
The hideHeaderOnScroll plugin is jQuery dependent.
(function($){
$(document).ready(function () {
$("#header").hideHeaderOnScroll();
});
}(jQuery));
The hideHeaderOnScroll plugin can be customized.
(function($){
$(document).ready(function () {
$("#header").hideHeaderOnScroll({
hideAtScrollingHeight : 500,
speedEffect : 300,
hidingHeight : 100,
});
});
}(jQuery));
# How to install
- Download the hideHeaderOnScroll plugin.
- Unzip, and see how to use the plugin in the attached examples/index.html file.
-
Your header element need to be at fixed position.
For example, element with id of "header".
<div id="header"> <!--The content of your header.--> </div>
- The header element has to be fixed. For example, the css rules for the header can look something like this:
#header { /* The header has to be at fixed position*/ position:fixed; top: 0; right: 0; left: 0; z-index:10; overflow:hidden; width:100%; /* The header needs to have height */ height:119px; /* Change to your own colors */ border:1px solid #b3b3b3; background:#efefef; }
- Include the jQuery library before you include the hideHeaderOnScroll plugin.
<script src="assets/js/jquery.min.js"></script>
- Include the plugin file.
For example, if you extract the folder plugin straight to the root of your website:
<script src="assets/js/jquery.hideHeaderOnScroll.min.js"></script>
- Call the plugin on the header of your page.
<script> $("#header").hideHeaderOnScroll(); </script>
- You can customize the plugin with the options that are listed on this page.
For example:
<script> (function($){ $(document).ready(function () { $("#header").hideHeaderOnScroll({ hideAtScrollingHeight : 500, // The speed of the effect speed : 500, // Hide only 30px of the header. The default is false so all of the header is hidden. hidingHeight: 30, // onShow : function() { // alert("The header is now fully down/shown."); //}, // onHide : function() { // alert("The header is now fully up/hidden."); //}, }); }); }(jQuery)); </script>
# Settings
Property | Default | Description |
---|---|---|
hideAtScrollingHeight | 0 | How many pixels the user needs to scroll before the effect starts. |
speed | 250 | The speed at which the header element pops or hides. |
hidingHeight | false | How many pixels of the header needs to be hidden. i.e. value of 30 hides only 30px of the header. The default is false so all of the header is hidden. |
Callbacks
Callback | Description |
---|---|
onShow | Fires right after the header finishes to appear. |
onHide | Fires right after the header finishes to disappear. |
License
The MIT License (MIT)