Last active
August 29, 2015 14:14
-
-
Save JoanClaret/f6e7572aa290dee48936 to your computer and use it in GitHub Desktop.
Sticky layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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' | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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