Popover does not get anchored to the triggering element

前端 未结 2 1958
悲哀的现实
悲哀的现实 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()
                });
            });
        });
    });
    
    0 讨论(0)
  • 2021-01-03 02:11

    For BS 3 and above

    you can use container: $(element)

    Example:

    let elem = $(this)
    $(elem).popover({
        selector: '[rel=popover]',
        trigger: 'hover',
        container: $(elem),
        placement: 'bottom',
        html: true,
        content: 'Popover Content'
    });
    
    0 讨论(0)
提交回复
热议问题