Friday, 9 August 2013

jQuery - Stick div to bottom of window when out of view

jQuery - Stick div to bottom of window when out of view

Been searching a while for this, no real luck yet. and would kind of like
to do it without a plugin.
I am trying to make it so a selected div (footer) would come into view
when the page is being scrolled. I managed to find a way to do it for the
navigation menu at the top of the window, but it just seems harder for the
bottom part of the window..
Here's what I have used for the Top
$(window).bind("load", function() { // document ready
var stickyTop = $('#Sticky').offset().top; // returns number
$(window).scroll( function(){ // scroll event
var windowTop = $(window).scrollTop(); // returns number
if (stickyTop < windowTop) {
$('#Sticky').css({ position: 'fixed', top: 0});
}
else {
$('#Sticky').css('position','static');
}
});
});
and it works great. Anyway to modify this and use it for the same (if not
similar) effect at the bottom?
Also, sorry if I make little sense..

No comments:

Post a Comment