开发手册 欢迎您!
软件开发者资料库

Bootstrap - Popover插件

Bootstrap Popover插件 - 从概述,环境设置,基本结构,全局样式,网格系统,流体网格系统,布局,响应式设计,排版,表格,按钮,图像,图标,下拉列表,按钮开始,简单易学地学习Bootstrap组,导航元素,导航栏,面包屑,分页,标签,徽章,版式,缩略图,警报,进度栏,媒体对象,Javascript插件像过渡,模态,下拉列表,滚动,选项卡,工具提示,弹出,警报,按钮,折叠, Carousel,Typeahead,Affix,Glyphicons,Jumbotron,Demos。

popover类似于工具提示,提供带有标题的扩展视图.要激活弹出框,用户只需将光标悬停在元素上.可以使用Bootstrap Data API完全填充popover的内容.此方法需要工具提示.

如果您想单独包含此插件功能,那么您将需要 popover.js 并且它具有工具提示插件.另外,如 Bootstrap插件概述一章所述,您可以包含 bootstrap.js 或缩小 bootstrap.min.js .

用法

popover插件按需生成内容和标记,默认情况下会弹出窗口触发后的元素.您可以通过以下两种方式添加popover :

  • 通过数据属性 : 要添加弹出窗口,请将 data-toggle ="popover"添加到锚点/按钮标记.锚点的标题将是弹出窗口的文本.默认情况下,插件将popover设置为顶部.

   Hover over me

  • 通过JavaScript : 使用以下语法通过JavaScript启用弹出窗口 :

$('#identifier').popover(options)

Popover插件不仅仅是-css插件,比如前面章节中讨论的下拉列表或其他插件.要使用此插件,您必须使用jquery(读取javascript)激活它.要启用页面上的所有弹出框,只需使用此脚本 :

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

示例

以下示例演示如何通过数据属性使用popover插件.

               Popover on left                     Popover on top                     Popover on bottom                     Popover on right      

Options

某些选项可以通过Bootstrap Data API添加或通过JavaScript调用。 下表列出了选项:

Option NameType/Default ValueData attribute nameDescription
animationboolean Default − truedata-animationApplies a CSS fade transition to the popover.
htmlboolean Default − falsedata-htmlInserts HTML into the popover. If false, jQuery’s text method will be used to insert content into the dom. Use text if you’re worried about XSS attacks.
placementstring|function Default − topdata-placementSpecifies how to position the popover (i.e., top|bottom|left|right|auto).

When auto is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right.

selectorstring Default − falsedata-selectorIf a selector is provided, popover objects will be delegated to the specified targets.
titlestring | function Default − "data-titleThe title option is the default title value if the title attribute isn’t present.
triggerstring Default − 'hover focus'data-triggerDefines how the popover is triggered − click| hover | focus | manual. You may pass multiple triggers; separate them with a space.
delaynumber | object Default − 0data-delay

Delays showing and hiding the popover in ms — does not apply to manual trigger type. If a number is supplied, delay is applied to both hide/show. Object structure is −

delay: { show: 500, hide: 100 }
containerstring | false Default − falsedata-containerAppends the popover to a specific element. Example: container: 'body'

Methods

以下是一些有用的popover方法:

MethodDescriptionExample

Options − .popover(options)

Attaches a popover handler to an element collection.
$().popover(options)

Toggle − .popover('toggle')

Toggles an element's popover.
$('#element').popover('toggle')

Show − .popover('show')

Reveals an element's popover.
$('#element').popover('show')

Hide − .popover('hide')

Hides an element's popover.
$('#element').popover('hide')

Destroy − .popover('destroy')

Hides and destroys an element's popover.
$('#element').popover('destroy')

Example

以下示例演示了popover插件方法:

               Popover on left                     Popover on top                     Popover on bottom                     Popover on right      





            Title" data-container = "body"          data-toggle = "popover" data-content = "         

Some content in Popover-options method

">                  Popover         

      

Events

下表列出了使用popover插件的事件.此事件可用于挂钩函数.

事件描述示例
show.bs.popover调用show实例方法时会立即触发此事件.
  $('#mypopover').on('show.bs.popover',function(){//做点什么})
shown.bs.popover此事件在popover已经对用户可见(将等待CSS转换完成).
  $('# mypopover').on('shown.bs.popover',function(){//做点什么})
hide.bs.popover当隐藏实例方法具有此事件时,会立即触发此事件被叫.
  $('#mypopover').on('hide.bs.popover',function(){//做点什么})
hidden.bs.popover当popover完成对用户的隐藏时将触发此事件(将等待CSS转换完成).
  $('#mypopover').on('hidden.bs.popover',function(){//做点什么})

示例

以下示例演示Popover插件事件 :

               Popover on left