Create sticky elements that always visible as you scroll
- Get the target element's offset (
offset.left
andoffset.top
), put the the element's margin into account - As the document scrolls, when
window.scrollY
>=offset.top
, make the element sticky by setting it toposition: fixed
,top: 0
,left: [offset.left]px
- When resizing the window, un-sticky the element to recalculate
offset.left
, then make it sticky again
- Include jQuery (v1.2.6 or later) and jquery.sticky-float.js
- Call Sticky Float
$(function () {
$("#side-nav").stickyFloat();
});
- Don't use inline CSS on sticky elements
- Floating and container element must be positioned first