Sticky Sidebar jQuery plugin
Posted on March 21, 2011 by Phil 176 comments
This jQuery plugin allows you to set a number of sidebar or floating boxes that follow the user down the page as they scroll. The plugin uses absolute positioning calculated from the original css and offset to either the closest positioned parent or to the document. The plugin has been tested in IE6-9 and all the other major browsers.
The JavaScript (jQuery)
Below is the code for the plugin, to download the code with examples use the link above.
Usage
The plugin can be used for single or multiple boxes as shown in the examples below
A Single sticky sidebar
<div id="main">
<h2>Product catalogue</h2>
<ul id="products">
[...]
</ul>
</div>
<div id="side">
<div id="basket">
<h3>Your basket</h3>
<p>Total: <strong>£455.00</strong></p>
<span id="items">4</span>
</div>
</div>
For the above snippet of a HTML page we can use the following to enable the product basket as a sticky sidebar with the default options.
$('#basket').stickySidebar();
Multiple sticky boxes
<div id="left">
<h2>Left column</h2>
<ol id="navbox" class="stickybox">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ol>
</div>
<div id="middle"></div>
<div id="right">
<h2>Right column</h2>
<div id="basket" class="stickybox">
<h3>Your basket</h3>
<p>Total: <strong>£455.00</strong></p>
<span id="items">4</span>
</div>
</div>
For the above example we can use the below to set the navbox and basket boxes to both be sticky sidebars with the same options.
$('.stickbox').stickySidebar({speed: 400, padding: 30, constrain: true})
Options
The Sticky Sidebar plugin has four options:
- speed – how long the animation of the box should take in milliseconds (default = 250)
- easing – what type of easing to use for the animation (default = “linear”)
- padding – how many pixels to pad the element from the top of the window (default = 10)
- constrain – if true stops sticky scrolling out of parent
Methods
The Sticky Sidebar plugin has two methods:
- remove – removes the sticky selected sticky sidebars and resets to original position
- destroy – removes and resets all sticky sidebars and removes event listeners
Related Posts
No related posts.
176 Responses So Far
← Older Comments-
Pingback: 8 Cool jQuery Sticky Scroll Plugins | Graphic & Web Design Inspiration + Resources
-
Wesley Burden October 10, 2012 at 9:58 am
Phil – thanks for this wicked little plugin.
I’ve been having issues with containing the sidebar in it’s parent element and I believe 960 grid is to blame…
The stick sidebar was ignoring the parent element and continuing on beyond and over the site footer. After much fiddling it seems that 960gs is to blame. Once I removed the 960gs styles and replaced with my own it works fine.
Not exactly sure why 960gs causes this issue, I think either something to do with the clearfix it applies or the fact that it makes grid elements display:inline.
-
Pingback: Best jQuery Plugins for Web Development
-
Pingback: 25 Fabulous Essential jQuery Plugin ToolKit for Developers | Smashing Spy
-
Guido P. November 19, 2012 at 3:48 am
Hi there,
very nice plugin. Many thanks for that, but i got one little problem.
Imagine following structure:
################
# fixed header # <<– height: 100px
################
# main #
# col1 | col3 #
################
# footer #
################Acutally my submenu disappears from the fixed positionied header and when the scrolling reaches top: 0 – the submenu is getting repositioned correctly.
What i want to have is that repositioning of the sticky element – my submenu – starts at top: 100
How can i tell the script that theres a fixed 100px height header, and repositioning shold start at this offset??
With best regards
guido -
Pingback: 2012年度优秀jQuery插件精选100个 | 奶油天空
-
Gilad December 29, 2012 at 6:04 pm
Thanks a lot, this plugin look very good.
I have a question – if I want to limit the scrolling until it gets to my footer (and to scroll over it), how can I do that ?
Thanks a lot ! -
Pingback: 每个web开发者必备的40个jquery插件 | iluther-专注web技术iluther-专注web技术
-
Pingback: Project: Sticky Sidebar | Skillcrush
-
Chris January 30, 2013 at 6:37 pm
Hello,
this is a great plugin!
I was wondering if it’s possible to disable the sticky sidebar in case a #link is clicked?So I would have those 2 options:
#1: User scrolls page -> sticky sidebar plugin is active
#2: User clicks a link -> sticky sidebar is disabled till the page is scrolled again (#1)
I created a little fiddle for this scenario, but I’m not sure how to do that best.
http://jsfiddle.net/CeUcJ/I would be very thankful for your help!
-
Pingback: 25 Essential jQuery Plugin ToolKit for Developers - Baqar Abbas
-
Pingback: Week of 4/13/12 – TDAS Creative Wiki
-
Pingback: 分享9个滚动粘卷jQuery Sticky Scroll插件
-
Pingback: Sticky Scrolls - 12 Free Plugins | ViewLikeUs - Check Sites in Various Resolutions! | Blog





Hi there,
Just wondering if you’ve made this into a WordPress plugin?? That would be AWESOME!!
I’m working on a site that the customer has requested such a feature.