【问题标题】:Twitter Bootstrap: Popover vs Tooltip?Twitter Bootstrap:弹出框与工具提示?
【发布时间】:2012-04-08 06:02:58
【问题描述】:

这两者有什么区别?对我来说,Popover 看起来就像一个更大的 Tooltip,边框更厚。有什么质的区别,还是只是你想要它有多大胆?

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    Popovers 要求包含Tooltips。除了视觉上的差异之外,弹出框还可以选择显示标题和内容,而工具提示只有显示标题的选项。

    【讨论】:

    • 弹出框也可以用来显示图片,如下所示:stackoverflow.com/questions/11075560/…
    • Popover 也有“focus”作为触发值。它允许通过单击任意位置来关闭它。使用工具提示,您必须再次单击激活工具提示的对象。
    【解决方案2】:

    语义,您通常希望使用弹出框来提供额外的相关信息。您可以使用工具提示进行说明或提示。

    Popovers

    • 短或长
    • 可以包含各种内容(例如图像、标题、列表)
    • 通常可关闭,点击或悬停即可使用
    • 允许额外的交互(例如按钮)
    • 旨在提供有关所关注事物的其他相关上下文

    Tooltips

    • 只有少量文本(没有其他类型的内容)
    • 通常仅在悬停时可用
    • 旨在澄清或帮助您使用专注的事物

    A similar post from UX SE which explains well when to use which.


    技术上,差别不大。它们的工作方式相似。您可以使用data- 属性或JS。

    它们使用相同的库工作,因此具有许多相同的交互选项(悬停/焦点、内容包含、出现的一侧等)。

    代码示例:

    $(function() {
      $('.favorite').tooltip({
        placement: "right",
        title: "Click to mark as favorite question (click again to undo)"
      });
    
      $('.demo-start').popover({
        content: `
            <p>Walk through the components step by step! In this guide, you'll:</p>
            <ol>
              <li>Learn the semantics</li>
              <li>Learn the code</li>
              <li>Examine use cases</li>
            </ol>
            <div class="btn-group text-light d-flex justify-content-end" role="group" aria-label="Navigation buttons">
              <button type="button" class="btn btn-secondary" disabled><i class="fas fa-arrow-left mr-1"></i> Previous</button>
              <button type="button" class="btn btn-secondary">Next <i class="fas fa-arrow-right ml-1"></i></button>
            </div>
            `,
        html: true,
        placement: 'right',
        title: 'Welcome to the Tour!',
        trigger: 'hover focus'
      });
    });
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
    
    <a class="demo-start btn btn-dark m-5" href="#" role="button">
        <i class="fas fa-play text-light mr-1"> </i> Start the Demo</a>
    <br>
    <i class="favorite fas fa-star m-5 text-secondary"></i>
    
    
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    【讨论】:

      【解决方案3】:

      Popvers 只是工具提示的扩展,看起来有些不同,旨在提供更多内容。

      例如,弹出框有标题和内容部分,但工具提示只是内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多