Skip to content

Instantly share code, notes, and snippets.

@wangwen1220
Last active January 2, 2016 13:29
Show Gist options
  • Select an option

  • Save wangwen1220/8310412 to your computer and use it in GitHub Desktop.

Select an option

Save wangwen1220/8310412 to your computer and use it in GitHub Desktop.
JS: jQuery 生成一个自动停靠页尾效果 | position footer
// jQuery 生成一个自动停靠页尾效果
// Window load event used just in case window height is dependant upon images
$(window).bind("load", function() {
var footerHeight = 0;
var footerTop = 0;
var $footer = $("#footer");
positionFooter();
function positionFooter() {
footerHeight = $footer.height();
footerTop = ($(window).scrollTop() + $(window).height() - footerHeight) + "px";
if (($(document.body).height() + footerHeight) < $(window).height()) {
$footer.css({
position: "absolute"
}).stop().animate({
top: footerTop
});
} else {
$footer.css({
position: "static"
});
}
}
$(window).scroll(positionFooter).resize(positionFooter);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment