|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
FF3+ IE7+ Opera8+
Sticky Content script Author:
Dynamic Drive
Description: You most likely have seen it on the web somewhere- a menu or header bar that initially appears inline on the page like its peers, but as you scroll past it it continues to remain visible and fixed on the page. It's a novel way to keep important parts of your page "sticky". This simple jQuery script lets you do just that. It works by "fixing" a cloned copy of the desired element on the page while the former is out of view, and hiding the copy when the original is back in the limelight. Specify if the content should stop being "sticky" after x seconds, and also, whether to apply a CSS class to it while it is. Demo: Scroll the page and observe how the purple menu bar above stays fixed when it starts to get out of view. Step 1: Add the below script to the <HEAD> section of your page: It references the file stickycontent.js, which you should download now. Step 2: Add the below sample sticky content markup to the BODY section of your page: More InformationSticky Content script is packaged as a normal jQuery plugin. To make a content sticky on the page, simply call the following initialization code in the HEAD section of your page:
jQuery(function($){ //on DOM load
Where "selector" is the
jQuery
selector that references the element(s) you wish to make sticky, and jQuery(function($){ //on DOM load
The following shows all the available settings for the
When defining these settings, be sure to separate each one with a comma, with NO comma following the very last setting: jQuery(function($){ //on DOM load |