Bootstrap 3.0 affix with list changes width

前端 未结 9 1667
一向
一向 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:32

    My solution as well:

    $('.menu-card').affix();
    $(document).on('affix.bs.affix', '.menu-card', function() {
        $(this).width($(this).width());
    });
    

    (.menu-card is my sticky div)

    I added this for supporting the window resizing:

    Let's assume the affix are in a parent div #menu-card-pane.

    $(window).resize(function () {
        var parentSize = $('#menu-card-pane').width();
        $('.affix').each(function() {
            var affixPadding = $(this).innerWidth() - $(this).width();
            $(this).width(parentSize - affixPadding);
        });
    });
    

提交回复
热议问题