Bootstrap 3.1.0: affix too long

后端 未结 3 603
说谎
说谎 2021-02-10 01:18

I am using Bootstrap 3.1.0. When an \"affix\" gets too long for the viewport, it gets cut off, never showing bottom items.

Is there a possibility to have Bootst

相关标签:
3条回答
  • 2021-02-10 02:23

    I hope it can help you :

    Just add an overflow-y

    Jsfiddle : http://jsfiddle.net/Ja3XT/1/

    Added Css :

    #sidebar{
     max-height: 100%;
     overflow-y: auto;   
    }
    

    UPDATE AFTER COMMENT:

    fiddle : http://jsfiddle.net/F4FZL/1/

    JS :

    $('#sidebar').affix({
        offset: {
            top:100,
            bottom:0
        }
    });
    
    
    $('#sidebar').on('affixed.bs.affix', function(){
        $(this).removeAttr('style');
    });
    
    0 讨论(0)
  • 2021-02-10 02:23

    In my case I had a really long sidebar on the left side which i wanted to be scrollable at anytime. For me the solution was even easier than the aforementioned solutions:

    $('[data-spy="affix"]').on('affix.bs.affix', function (e) {
        e.preventDefault();
        return;
    });
    
    0 讨论(0)
  • 2021-02-10 02:24

    I had the same issue. I spent a few hours and finnaly I wrote the following solution:

    $('#sidebar').on('affix.bs.affix', function (e) {
        var $this = $(this),
            affix = $this.data('bs.affix'),
            offset = affix.options.offset,
            offsetBottom = offset.bottom;
    
        if (typeof offset != 'object') {
            offsetBottom = offset;
        }
    
        if (typeof offsetBottom == 'function') {
            offsetBottom = offset.bottom($this);
        }
    
        if ($this.outerHeight() + $this.offset().top + offsetBottom === Math.max($(document).height(), $(document.body).height())) {
            e.preventDefault();
        }
    });
    

    You can see code at http://jsfiddle.net/F4FZL/10/ and play with demo at https://jsfiddle.net/F4FZL/10/embedded/result/.

    Hope this information will be helpful.

    0 讨论(0)
提交回复
热议问题