keep bootstrap popover inside viewport

前端 未结 2 1131
傲寒
傲寒 2021-02-07 13:16

I am trying to create a menu using a sidebar with buttons, each one with an assigned popover containing the relevant data. Unfortunately, one of the popovers might contain an ar

相关标签:
2条回答
  • 2021-02-07 14:01

    Fixed in the upcoming Bootstrap v3.2.0 I believe: http://jsfiddle.net/pkP77/1/

    Courtesy of the new viewport feature introduced in https://github.com/twbs/bootstrap/pull/12328

    0 讨论(0)
  • 2021-02-07 14:05

    You can always override the top value of the popover using !important This might not be the best long term plan as it might interfere with future CSS changes

     .popover {
            width: 300px !important;
            top: 0px !important;
        }
    

    http://jsfiddle.net/smurphy/x9hnk/

    Update:

    Going off of the event you mentioned this seems to work.

    $('.btn-popover').on('shown.bs.popover', function (event) {
        //Set timeout to wait for popup div to redraw(animation)
        setTimeout(function(){
            if($('div.popover').css('top').charAt(0) === '-'){
                 $('div.popover').css('top', '0px');
                 var buttonTop = $(event.currentTarget).position().top;
                 var buttonHeight = $(event.currentTarget).height();
                 $('.popover.left>.arrow').css('top', buttonTop + (buttonHeight/2));
            }
        },100);
    });
    

    http://jsfiddle.net/smurphy/e6YaY/2/

    This aligns the arrow with your button. enter image description here

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