This can now be achieved without javascript using position: sticky.
Updated fiddle: http://jsfiddle.net/p1gku0mx/3/
The key is to wrap the sticky element in another div. Since the sticky element cannot move outside of its wrapper div it get scrolled up when the footer comes into view.