简体   繁体   English

自举弹出窗口动态更改位置从上到下

[英]bootstrap popover dynamic change position from top to bottom

I have a problem with bootstrap popover, i can't figure how to change popover position from top to bottom when it reaches top of the viewport. 我在使用引导程序弹出窗口时遇到问题,当弹出窗口到达视口顶部时,我无法确定如何从顶部到底部更改弹出窗口的位置。 I tried to use 我尝试使用

placement: 'auto bottom' but this doesn't work for me. 展示位置:“自动底部”,但这对我不起作用。

$(function(){
var options = {
    placement: function (context, element) {
        var position = $(element).position();
        console.log(position.top - $(window).scrollTop());
        if (position.top - $(window).scrollTop() < 110){
            return "bottom";
        }
        return "top";
    }, html: true
};
$(".popover-link").popover(options);
});

update 更新

this worked for me, for "popover" in top, but popover at the bottom gets negative position, and it's always shows at the bottom 这对我有用,对于顶部的“弹出式窗口”有效,但是底部的弹出式窗口位置为负数,并且始终显示在底部

you need to use data-placement="auto top" which will allow the popover to go to the top if possible but if not - then to the bottom of the element. 您需要使用data-placement="auto top" ,如果可能的话,弹出窗口将跳至顶部,但如果不能,则跳至该元素的底部。

To summarise you state the position that you want and if it can't do that it does the opposite - (same as auto left will allow it to go left if possible but right if not). 总而言之,您要声明所需的位置,如果无法做到,则相反-(与“自动左”相同,如果可能,则向左移动,否则,则向右移动)。

<a href="#" title="Sample Title" data-toggle="popover" data-placement="auto top" data-content="Sample Content">Click</a>

Just do it by data-placement="bottom" 只需通过data-placement =“ bottom”即可

 <a href="#" title="Header" data-toggle="popover" data-placement="bottom" data-content="Content">Click</a>

Hope it Helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM