Bootstrap 3.0 affix with list changes width

前端 未结 9 1765
一向
一向 2021-02-01 14:56

I\'m migrating to bootstrap 3.0.0 and I\'m having issues with an affixed menu to the left: as soon as it becomes affixed (after 10px scroll), its width changes. In this fiddle i

9条回答
  •  轮回少年
    2021-02-01 15:34

    I use this code to fix the width of the affix.

    $(document).on('affixed.bs.affix',function(e){
        $('.affix').each(function(){
            var elem = $(this);
            var parentPanel = $(elem).parent();
            var resizeFn = function () {
                var parentAffixWidth = $(parentPanel).width();
                elem.width(parentAffixWidth);
            };      
    
            resizeFn();
            //$(window).resize(resizeFn);
        });
    });
    

    The affix get the width of his parent and check that width on every scroll the web. Uncommenting the last line, execute too on resize window event.

提交回复
热议问题