案例

受到Jason Frame开发的jQuery.tipsy插件的启发,我们才把这个工具提示插件做的更好,而且此插件不依赖图片,只是使用CSS3来实现动画效果,并使用data属性存储标题。

将鼠标悬停到下面的链接上就可以看到工具提示了:

代码段:

  1. <script type="text/javascript">
  2. $(function() {
  3. $('.tooltip-demo').tooltip({
  4. selector: "[data-toggle=tooltip]",
  5. container: "body"
  6. })
  7. $("#testt").tooltip({})
  8. $('a').tooltip()
  9. })
  10. </script>
  1. <div class="bs-example tooltip-demo">
  2. <p class="muted" style="margin-bottom: 0;">Tight pants next level keffiyeh
  3. <a href="#" data-toggle="tooltip" title="Default tooltip">you probably</a>
  4. haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown.
  5. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel
  6. <a href="#" data-toggle="tooltip" title="Another tooltip">have a</a>
  7. terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats.
  8. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray.    A really ironic artisan
  9. <a href="#" data-toggle="tooltip" title="Another one here too">whatever keytar</a>
  10. , scenester farm-to-table banksy Austin
  11. <a href="#" data-toggle="tooltip" title="The last tip!">twitter handle</a>
  12. freegan cred raw denim single-origin coffee viral.
  13. </p>
  14. </div>

预览:

图片无法上传了。。。。。。。。我去去去去去去去。。。。。!!

四个展示方位

左侧Tooltip 上方Tooltip 下方Tooltip 右侧Tooltip

选择性加入的功能

出于性能方面的考虑,工具提示和弹框组件的data属性api是选择性加入的,也就是说你必须自己初始化他们。

工具提示与按钮组和输入框组联合使用时需要一些特殊设置

.btn-group 或 .input-group内的元素上使用工具提示时,你需要指定container: 'body'选项以避免不需要的副作用(例如,当工具提示显示之后,与其合作的页面元素可能变得更宽或是去圆角)。

在禁止使用的页面元素上使用工具提示时需要额外增加一个元素将其包裹起来

为了给disabled 或.disabled元素添加工具提示,将需要增加工具提示的页面元素包裹在一个<div>中,然后对这个<div>元素应用工具提示。

用法

通过JavaScript激活工具提示:

$('#example').tooltip(options)

Markup

The generated markup of a tooltip is rather simple, though it does require a position (by default, set to top by the plugin).

<div class="tooltip">
<div class="tooltip-inner">
Tooltip!
</div>
<div class="tooltip-arrow"></div>
</div>

选项

可以将选项通过data属性或JavaScript传递。对于data属性,需要将选项名称放到data-之后,例如data-animation=""

名称 类型 默认值 描述
animation boolean true apply a CSS fade transition to the tooltip
html boolean false Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.
placement string | function 'top' how to position the tooltip - top | bottom | left | right | auto.  When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.
selector string false If a selector is provided, tooltip objects will be delegated to the specified targets.
title string | function '' default title value if title attribute isn't present
trigger string 'hover focus' how tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.
delay number | object 0

delay showing and hiding the tooltip (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 }

container string | false false

Appends the tooltip to a specific element. Example: container: 'body'

对单个工具提示使用data属性

使用data属性可以为单个工具提示指定额外选项,如下所示。

标记

<a href="#" data-toggle="tooltip" title="first tooltip">Hover over me</a>

方法

$().tooltip(options)

为一组元素应用工具提示。

.tooltip('show')

展示工具提示。

$('#element').tooltip('show')

.tooltip('hide')

隐藏工具提示。

$('#element').tooltip('hide')

.tooltip('toggle')

展示或隐藏工具提示。

$('#element').tooltip('toggle')

.tooltip('destroy')

隐藏并销毁工具提示。

$('#element').tooltip('destroy')

事件

事件类型 描述
show.bs.tooltip show方法被调用之后,此事件将被立即触发。
shown.bs.tooltip 当工具提示展示到用户面前之后(同时CSS过渡效果执行完之后)此事件被触发。
hide.bs.tooltip hide方法被调用之后,此事件被触发。
hidden.bs.tooltip 当工具提示被隐藏之后(同时CSS过渡效果执行完之后),此事件被触发。
$('#myTooltip').on('hidden.bs.tooltip', function () {
// do something…
})

Bootstrap学习js插件篇之提示框的更多相关文章

  1. Bootstrap学习js插件篇之标签页

    简单的标签页 代码: <h1 class="page-header">4.3标签页</h1> <ul class="nav nav-tabs ...

  2. Bootstrap学习js插件篇之滚动监听

    1.滚动监听 案例 滚动监听插件可以根据滚动条的位置自动更新所对应的导航标记.Bootstrap中文网左侧就是一个滚动监听的例子. 代码段: <nav id="navbar-examp ...

  3. Bootstrap学习js插件篇之下拉菜单

    案例 通过此插件可以为几乎所有东西添加下拉菜单,包括导航条.标签页.胶囊式按钮. 用于导航条 导航条分为四个部分.第一部分导航头,第二部分导航列,第三部分form查询表单,第四部分导航列. <n ...

  4. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-1导入JavaScript插件

    导入JavaScript插件 Bootstrap除了包含丰富的Web组件之外,如前面介绍的下拉菜单.按钮组.导航.分页等.他还包括一些JavaScript的插件. Bootstrap的JavaScri ...

  5. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-3 模态弹出框

    模态弹出框(Modals) 这一小节我们先来讲解一个“模态弹出框”,插件的源文件:modal.js. 右侧代码编辑器(30行)就是单独引入 bootstrap 中发布出的“modal.js”文件. 样 ...

  6. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-4 模态弹出框--结构分析

    模态弹出框--结构分析 Bootstrap框架中的模态弹出框,分别运用了“modal”.“modal-dialog”和“modal-content”样式,而弹出窗真正的内容都放置在“modal-con ...

  7. 《玩转Bootstrap(JS插件篇)》笔记

    导入JavaScript插件 不论是单独导入还一次性导入之前必须先导入jQuery库. 一次性导入 <script src="js/bootstrap.min.js"> ...

  8. bootstrap学习——javascript插件篇

    飞近期做的一个小项目须要用到一个模态框和一个图片浏览插件,并把二者结合,刚好bootstrap有相应插件,下面是学习应用流程: 1.    引入js文件: 能够单个引入相应插件文件,或一次所有引入.飞 ...

  9. Bootstrap的js插件之弹出框(popover)

    data-toggle="popover"--使弹出框可以切换状态: title--设置弹出框的标题: data-content--设置弹出框的内容部分: data-placeme ...

随机推荐

  1. 1009 Product of Polynomials (25)(25 point(s))

    problem This time, you are supposed to find A*B where A and B are two polynomials. Input Specificati ...

  2. BZOJ 1283 序列 费用流 网络流 线性规划

    https://darkbzoj.cf/problem/1283 给出一个长度为N的正整数序列Ci,求一个子序列,使得原序列中任意长度为M的子串中被选出的元素不超过K(K,M<=100) 个,并 ...

  3. SpringBoot+SpringSecurity+Thymeleaf认证失败返回错误信息踩坑记录

    Spring boot +Spring Security + Thymeleaf认证失败返回错误信息踩坑记录 步入8102年,现在企业开发追求快速,Springboot以多种优秀特性引领潮流,在众多使 ...

  4. Python168的学习笔记6

    如何派生内置不可变类型并修改实例化行为. 个人理解,如何派生出自己想要的类. class IntTuple(tuple): def __new__(cls,iterable): g = (x for ...

  5. MySQL的五种日期和时间类型

          MySQl中有多种表示日期和时间的数据类型.其中YEAR表示年份,DATE表示日期,TIME表示时间,DATETIME和TIMESTAMP表示日期和实践.它们的对比如下:YEAR ,字节数 ...

  6. GoAhead2.5移植到ARM教程

    1.下载GoAhead2.5 下载地址:https://github.com/embedthis/goahead/releases?after=v3.1.2 2.编译 先解压到虚拟机的/opt目录下, ...

  7. ThinkPHP通过类的链式继承优化空操作的实现

    上篇<ThinkPHP空操作和空控制器的处理>中,在处理空操作时修改了父类Controller.class.php中代码,不到万不得已不能 修改基类控制器中的原码,此时可在子类与父类之间, ...

  8. windows命令行快捷操作

    net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" /user: ...

  9. 解决Oracle11g空表无法导出的问题

    Oracle11g 新增參数deferred_segment_creation  ,建库的时候默认值为true,意思是延时载入,当表中不存在数据的时候,不为这个表创建空间,当你导出的时候会发现非常多表 ...

  10. 在EntityFramework6中管理DbContext的正确方式——3环境上下文DbContext vs 显式DbContext vs 注入DbContext(外文翻译)

    (译者注:使用EF开发应用程序的一个难点就在于对其DbContext的生命周期管理,你的管理策略是否能很好的支持上层服务 使用独立事务,使用嵌套事务,并行执行,异步执行等需求? Mehdi El Gu ...