I have been looking for some time now for a solution to my sticky sidebar problem. I have a specific idea of how I would like it to act; effectively, I would like it to stick to the bottom as you scroll down, and then as soon as you scroll back up I would like it to stick to the top, in a fluid motion (no jumping). I am unable to find an example of what I am trying to achieve, so I have created an image that I hope will illustrate the point clearer:
- Sidebar sits under the header.
- As you scroll down the sidebar remains level with the content of the page so that you can scroll through both sidebar and content.
- Reach the bottom of the sidebar, the sidebar sticks to the bottom of the viewport (most plugins only allow for sticking to top, some that allow for sticking to bottom don't allow for both).
- Reach the bottom, sidebar sits above the footer.
- As you scroll back up, the sidebar stays level with the content so you can scroll through the content and sidebar again.
- Reach the top of the sidebar, the sidebar sticks to the top of the viewport.
- Reach the top and the sidebar sits back below the header.
I hope this is enough information. I have created a jsfiddle to test any plugins/scripts, which I have reset for this question: http://jsfiddle.net/jslucas/yr9gV/2/ .
Here's an example of how to implement this:
JavaScript:
CSS:
Demo: http://jsfiddle.net/ryanmaxwell/25QaE/
This works as expected in all scenarios and is well-supported in IE too.
I was looking for the exact same thing. Apparently I needed to search for some obscure terms just to find a similar question with the graphic. Turns out it's exactly what I was looking for. I couldn't find any plugins so I decided to make it myself. Hopefully someone will see this and refine it.
Here's a quick and dirty sample html I'm using.
Here's the jQuery I made:
Some notes:
If anyone can refine this a bit more that'd be great.
+1 to the very nice and ilustrative image.
I know it's an old question, but I casually found the same question posted by you in forum.jquery.com and one answer there (by@tucker973), suggested one nice library to make this and wanted to share it here.
It's called sticky-kit by @leafo
Here you have the code of a very basic example that I prepared and a working demo to see the result.
Of course, all credits go to the creator of the plugin, I only made this example to show it here. I need to accomplish the same result that you was after and found this plugin very useful.
Thanks for the great graphic. I was also looking for a solution to this challenge!
Unfortunately, the other answer posted here doesn't address requirement #5 that stipulates the ability to scroll back through the sidebar smoothly.
I created a fiddle that implements all requirements: http://jsfiddle.net/bN4qu/5/
The core logic that needs to be implemented is:
In the fiddle I use CSS3 transform for moving the target element around, so it won't work in e.g. IE<9. The logic is sound though for using a different approach.
Also, I modified your fiddle so that the sticky sidebar has a gradient background. This helps to show that the proper behavior is being exhibited.
I hope this is useful to someone!
Working Example: https://jsfiddle.net/L7xoopst/6/
There is a relatively unknown plugin in Wordpress repository known as WP Sticky Sidebar. The plugin does exactly what you wanted (Sticky sidebar: stick to bottom when scrolling down, top when scrolling up) WP Sticky Sidebar Wordpress repository Link: https://wordpress.org/plugins/mystickysidebar/