Popover does not get anchored to the triggering element

前端 未结 2 1968
悲哀的现实
悲哀的现实 2021-01-03 01:43

So my Twitter Bootstrap popovers seem to be positionally challenged when the triggering element is contained within an element with the style

2条回答
  •  孤独总比滥情好
    2021-01-03 01:48

    Parent element (offsetParent) of popover need to not be static, you could postionned it relatively to document:

    position: relative;

    See jsFiddle

    EDIT: for your use case, you could bind onscroll event of container and use following snippet:

    SEE jsFiddle

    $(function () {
        $('#example').popover();
        $('div').on('scroll', function () {
            var $container = $(this);
            $(this).find('.popover').each(function () {
                $(this).css({
                    top:  - $container.scrollTop()
                });
            });
        });
    });
    

提交回复
热议问题