I want the footer be just below the window in the initial position and when I resize the window. I need to declare the var outside and again inside the function to make it work. Is it ok or there is a better way to do it?
$(function(){
// initial position:
var docHeight = $(window).height();
$('#footer').css('margin-top', docHeight + 'px');
// position when I resize the window:
$(window).resize(function() {
var docHeight = $(window).height();
$('#footer').css('margin-top', docHeight + 'px');
});
})
I have the code here to play: http://jsfiddle.net/dWpp5/