[ Working demo ]
var el = $("#sticky"); var win = $(window); var width = el.width(); var height = el.height(); var win_height = $(window).height(); window.onscroll = function() { var offset = el.offset().top + height - win_height; if ( win.scrollTop() > offset ) { window.onscroll = function() { el.css({ width: width, position: "absolute", top: win.scrollTop() + win_height - height }); }; } };
If you do not need to support IE-based browsers, you can use:
position: "fixed" bottom: 0
source share