Fixed Position with javascript

Achieving position fixed functionality without JavaScript.

by Aamir Shahzad

HTML

<div id="footer">Footer Div</div>

CSS

body {
    height: 2000px;
}
#footer
{
    position: absolute;
    bottom: 10px;
}

JavaScript

$(document).ready(function () {
    
    var winHeight = $(window).height();
    
    $(window).scroll(function () {
        $("#footer").css("top", $(window).scrollTop() + (winHeight-30) + "px");
    });

});