当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Bootstrap弹出框(Popover)被挤压的问题小结

Bootstrap弹出框(Popover)被挤压的问题小结

2017年12月12日  | 移动技术网IT编程  | 我要评论

比较了下bootstrap的popover和一些其它的开源项目,觉得bootstrap的还算不错。没想到第一次就遇到了一个问题。

弹出框显示的时候如果贴近一个列的边沿,就会很窄,如果一个列比较宽还好,而如果遇到这样的列比如:<div class="col-md-2">,几乎任意位置显示的弹出框都被挤压了。

先看看我的实现以及效果:

js:

$(function (){
 $("[data-toggle='popover']").popover({
  trigger: 'hover'
 });
});

html:

<div class="col-md-1">
 ...
 <img src="..." width="50" height="50" data-toggle="popover" data-content='...' title="..." />
 ...
</div>

效果

f92657e0-9ceb-474c-821f-648273495c01.png

不过解决起来很简单,只需在初始化的时候添加一个container属性就可以了:

$(function (){
 $("[data-toggle='popover']").popover({
  trigger: 'hover',
 container: 'body'
 });
});

我们把容器设置成整个页面的body,这样popover就有足够宽的地方了。

1c8a50ed-88b6-44ab-928b-de0911386a60.png

实际上在官网上对container的作用是有说明的地址  ,只是没有注意到:

appends the popover to a specific element. example: container: 'body'. this option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.

以上所述是小编给大家介绍的bootstrap弹出框(popover)被挤压的问题小结,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网