Skip to content

Instantly share code, notes, and snippets.

@bh-lay
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save bh-lay/36e98d0444ff5636c6d3 to your computer and use it in GitHub Desktop.

Select an option

Save bh-lay/36e98d0444ff5636c6d3 to your computer and use it in GitHub Desktop.
stickyFooter
function stickyFooter($footer){
var $window = $(window);
//计算位置
function fix() {
$footer.css({
position: "static"
});
if ($window.height() < document.body.scrollHeight) {
$footer.css({
position: "static"
});
} else {
$footer.css({
position: "absolute",
bottom: 0
});
}
}
fix();
$window.resize(fix);
var timer = setInterval(fix,500);
return {
fix: fix,
destory : function(){
$window.unbind('resize',fix);
clearInterval(timer);
}
};
}
stickyFooter($("#footer"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment