欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

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

时间:2021-05-07 10:50:12|栏目:JavaScript代码|点击:

比较了下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.

上一篇:JavaScript中使用构造器创建对象无需new的情况说明

栏    目:JavaScript代码

下一篇:js贪吃蛇游戏实现思路和源码

本文标题:Bootstrap弹出框(Popover)被挤压的问题小结

本文地址:http://www.codeinn.net/misctech/116699.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有