I try to make sure that a div "filter" becomes fixed when scrolling and then stop when it comes down to "outside_footer_wrapper". use the following script but can not get it to work?
$(function() {
var top = $('#filter').offset().top - parseFloat($('#filter').css('marginTop').replace(/auto/, 0));
var footTop = $('#outside_footer_wrapper').offset().top - parseFloat($('#outside_footer_wrapper').css('marginTop').replace(/auto/, 0));
var maxY = footTop - $('#filter').outerHeight();
$(window).scroll(function(evt) {
var y = $(this).scrollTop();
if (y > top) {
if (y < maxY) {
$('#filter').addClass('fixed').removeAttr('style');
} else {
$('#filter').removeClass('fixed').css({
position: 'absolute',
top: (maxY - top) + 'px'
});
}
} else {
$('#filter').removeClass('fixed');
}
});
});
Is it something like this?
jsfiddle
try this:
jsfiddle here
if you know at which pixel number the filter have to be fixed and at which pixel number the footer starts you can try this function:
scrollTop
If you want to stop the
position:fixed
after you reach the footer you can do something like this faking with thetop
:Also take in care with the CSS for the class
fixed
you need to make that with equal specificity of #filter I made this change:Check This Demo Fiddle