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

Bootstrap - Modal插件

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

模态是在其父窗口上分层的子窗口.通常,目的是显示来自单独源的内容,该源可以在不离开父窗口的情况下进行一些交互.子窗口可以提供信息,交互等.

如果要单独包含此插件功能,则需要 modal.js .另外,如 Bootstrap插件概述一章所述,您可以包含 bootstrap.js 或缩小 bootstrap.min.js .

用法

您可以切换模态插件的隐藏内容 :

  • 通过数据属性 : 在控制器元素(如按钮或链接)上设置属性 data-toggle ="modal"以及 data-target ="#identifier" href ="#identifier"以特定模式(使用id ="identifier")进行切换.

  • 通过JavaScript : 使用这种技术,您可以使用一行JavaScript来调用id ="identifier"的模态;

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


示例

静态模态窗口示例显示在以下示例中 :

Example of creating Modals with Twitter Bootstrap

   Launch demo modal                                                            ×                                                   This Modal title                     
                              Add some text here         
                                             Close                                                   Submit changes                                         

 

上述代码的详细信息:

1、要调用模态窗口,您需要具有某种触发器。您可以使用按钮或链接。这里我们使用了一个按钮。

2、如果您查看上面的代码,您将看到在                                                         ×                                                   This Modal title                                                   Press ESC button to exit.                                                      Close                                                   Submit changes                                          

只需单击Esc按钮,即可退出模态窗口。

Events

下表列出了使用模态的事件。 这些事件可用于挂钩函数。

EventDescriptionExample
show.bs.modalFired after the show method is called.
$('#identifier').on('show.bs.modal', function () {   // do something…})
shown.bs.modalFired when the modal has been made visible to the user (will wait for CSS transitions to complete).
$('#identifier').on('shown.bs.modal', function () {   // do something…})
hide.bs.modalFired when the hide instance method has been called.
$('#identifier').on('hide.bs.modal', function () {   // do something…})
hidden.bs.modalFired when the modal has finished being hidden from the user.
$('#identifier').on('hidden.bs.modal', function () {   // do something…})

Example

以下示例演示了事件的用法:

Example of using events of Modal Plugin

   Launch demo modal                                                         ×                                                   This Modal title                                                   Click on close button to check Event functionality.                                                      Close                                                   Submit changes                                          

如上图所示,如果您点击关闭按钮即隐藏事件,则会显示警告信息.