Skip to content

Instantly share code, notes, and snippets.

@JoanClaret
Last active August 29, 2015 14:14
Show Gist options
  • Save JoanClaret/f6e7572aa290dee48936 to your computer and use it in GitHub Desktop.
Save JoanClaret/f6e7572aa290dee48936 to your computer and use it in GitHub Desktop.
Sticky layer
$(function() {
var $el = $('.sticky-layer');
var $window = $(window);
$window.bind("scroll resize", function() {
var elHeight = $el.outerHeight();
var windowHeight = $window.height();
var scrolledHeight = $window.scrollTop();
if ((windowHeight + scrolledHeight) > elHeight ){
$el.css({
bottom: "0",
top: 'auto',
position: 'fixed'
});
}else{
$el.css({
top: "0",
bototm:'auto',
position: 'absolute'
});
}
});
});
@JoanClaret
Copy link
Author

Disclaymer: Since it doesn't work as fine as expected, some improvements are needed. Feel free to collaborate.
DEMO: http://codepen.io/joanclaret/pen/wBrQQg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment