• Hi, I have a custom made sidebar which becomes fixed after scrolling the page for a certain amount of pixels. In order to do so I’ve implemented a jQuery script which should also prevent the sidebar from going below the footer when reaching it. The script adds a position:fixed or a position:absolute property to the sidebar, based on certain parameters. While it works for making the sidebar fixed after some scrolling, it doesn’t seem to do anything for the footer issue.
    I’ve put the following script in the custom javascript section of my theme:

    jQuery(document).ready(function () {
    
        var length = jQuery('#left').height() - jQuery('#sidebar').height() + jQuery('#left').offset().top;
    
        jQuery(window).scroll(function () {
    
            var scroll = jQuery(this).scrollTop();
            var height = jQuery('#sidebar').height() + 'px';
    
            if (scroll < jQuery('#left').offset().top) {
    
                jQuery('#sidebar').css({
                    'position': 'absolute',
                    'top': '0'
                });
    
            } else if (scroll > length) {
    
                jQuery('#sidebar').css({
                    'position': 'absolute',
                    'bottom': '0',
                    'top': 'auto'
                });
    
            } else {
    
                jQuery('#sidebar').css({
                    'position': 'fixed',
                    'top': '0',
                    'height': height
                });
    
            }
        });
    
    });

    It actually works when trying it on jsfiddle, here’s the link to some dummy code to show what i’m trying to accomplish.
    What am I doing wrong? Thanks for the help!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘stop fixed sidebar before footer’ is closed to new replies.