No matter how you scroll, the div
should always be at the bottom of the web page. Is there a solution using jQuery?
EDIT:
Should make it work in IE6.
No matter how you scroll, the div
should always be at the bottom of the web page. Is there a solution using jQuery?
EDIT:
Should make it work in IE6.
You can achieve that with pure css. Here's an excerpt (taken from http://groups.google.com/group/jquery-en/msg/3b877c156facb54d):
#footer {
position: absolute;
height: 50px;
width: 300px;
bottom: 0px;
left: 10px;
}
No need of javascript. CSS could do that...
#footer {
position: fixed;
width: 100%;
height: 50px;
left: 0;
bottom: 0
}
To set the appropriate style with jQuery you can do:
$('#footer').css({
position: "fixed",
width: "100%",
height: "50px",
left: 0,
bottom: 0
});
<style type="text/css">
#bottom {
position: fixed;
bottom: 0;
}
</style>
position:fixed is the solution for all browsers but ie6
There's plenty of solutions to make position fixed to work with ie6
But all time you'll do it you'll loose some other functionnality in other browsers (position:relative and absolute loosed), or you'll need css expressions and they will slow down the browser
http://www.cssplay.co.uk/layouts/fixed.html (css loose of relative and absolute) http://tagsoup.com/cookbook/css/fixed/bottom/ http://limpid.nl/lab/css/fixed/footer
Seriously stop developing for ie6 ! :)
<html>
<head>
<style type="text/css">
#theFooter {
position:absolute;
height:100px;
width:100px;
background-color:blue;
}
</style>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$("document").ready(function () {
function recalculate(event) {
var footer = $("#theFooter");
var theWindow = $(window);
var elementHeight = footer.height();
var windowHeight = theWindow.height();
var scrollTop = theWindow.scrollTop();
footer.css("top", windowHeight - elementHeight + scrollTop);
}
$(window).bind("resize scroll", recalculate);
recalculate();
});
</script>
</head>
<body>
<div id="theFooter">
Some Content.
</div>
</body>
</html>