Popover 组件类似于工具提示;它是当用户单击某个元素时出现的弹出框。不同之处在于弹出窗口可以包含更多内容。
有关 Popover 的教程,请阅读我们的Bootstrap 弹出窗口教程。
这个data-toggle="popover"
激活弹出窗口。
这个title
属性指定弹出窗口的标题文本。
这个data-content
属性指定应显示在弹出窗口主体内的文本。
<a href="#" data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">Toggle popover</a>
亲自试一试 »
Popover 不是纯 CSS 插件,因此必须使用 jQuery 进行初始化:选择指定的元素并调用 popover()
方法。
// Select all elements with data-toggle="popover" in the document
$('[data-toggle="popover"]').popover();
// Select a specified element
$('#myPopover').popover();
亲自试一试 »
选项可以通过数据属性或 JavaScript 传递。对于数据属性,请将选项名称附加到 data-,如 data-placement=""。
Name | Type | Default | Description | 尝试一下 |
---|---|---|---|---|
animation | boolean | true | Specifies whether to add a CSS fade transition effect when opening and closing the popover
|
尝试一下 |
container | string, or the boolean false | false | Appends the popover to a specific element. Example: container: 'body' |
尝试一下 |
content | string | "" | Specifies the text inside the popover's body | 尝试一下 |
delay | number, or object | 0 | Specifies the number of milliseconds it will take to open and close the popover. To specify a delay for opening and another one for closing, use the object structure: delay: {show: 500, hide: 100} - which will take 500 ms to open the popover, but only 100 ms to close it |
尝试一下 |
html | boolean | false | Specifies whether to accept HTML tags in the popover:
When set to false (default), jQuery's text() method will be used. Use this if you are worried about XSS attacks |
尝试一下 |
placement | string | "right" | Specifies the popover position. Possible values:
|
尝试一下 |
selector | string, or the boolean false | false | Adds the popover to a specified selector | 尝试一下 |
template | string | Base HTML to use when creating the popover. The popover's title will be injected into the .popover-header. The popover's content will be injected into the .popover-body. .arrow will become the popover's arrow. The outermost wrapper element should have the .popover class. |
||
title | string | "" | Specifies the header text of the popover | 尝试一下 |
trigger | string | "click" | Specifies how the popover is triggered. Possible values:
|
尝试一下 |
offset | number or a string | 0 | Offset of the popover relative to its target | |
fallbackPlacement | string or an aray | "flip" | Specifies which position Popper wil use on fallback | |
boundary | string or element | "scrollParent" | Overflow constraint boundary of the popover. Accepts the values "viewport", "window" or "scrollParent", or an HTML element |
下表列出了所有可用的弹出窗口方法。
Method | Description | 尝试一下 |
---|---|---|
.popover(options) | Activates the popover with an option. See options above for valid values | 尝试一下 |
.popover("show") | Shows the popover | 尝试一下 |
.popover("hide") | Hides the popover | 尝试一下 |
.popover("toggle") | Toggles the popover | 尝试一下 |
.popover("dispose") | Hides and destroys the popover | 尝试一下 |
.popover("enable") | Enables the popover the ability to be shown. This is default | |
.popover("disable") | Removes the ability to show a popover. The popover can only be shown if it is re-enabled again | |
.popover("toggleEnabled") | Toggles the ability for the popover to be shown or hidden | |
.popover("update") | Updates the position of the popover |
下表列出了所有可用的弹出窗口事件。
Event | Description | 尝试一下 |
---|---|---|
show.bs.popover | Occurs when the popover is about to be shown | 尝试一下 |
shown.bs.popover | Occurs when the popover is fully shown (after CSS transitions have completed) | 尝试一下 |
hide.bs.popover | Occurs when the popover is about to be hidden | 尝试一下 |
hidden.bs.popover | Occurs when the popover is fully hidden (after CSS transitions have completed) | 尝试一下 |
inserted.bs.popover | Occurs after the show.bs.popover event when the popover template has been added to the DOM |