Custom Tooltips——自定义工具提示


This example shows how to customize the buttons tooltips with Bootstrap.
这个例子用来展示如何使用Bootstrap来自定义按钮的提示。

代码:
<!DOCTYPE html>
<html>
  <head>
    <title>Custom Tooltips</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v4.2.0/build/ol.js"></script>
    <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <style>
      .tooltip-inner {
        white-space: nowrap;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        target: 'map',
        view: new ol.View({
          center: [-8730000, 5930000],
          rotation: Math.PI / 5,
          zoom: 8
        })
      });

      //设置提示位置
      $('.ol-zoom-in, .ol-zoom-out').tooltip({
        placement: 'right'
      });
      $('.ol-rotate-reset, .ol-attribution button[title]').tooltip({
        placement: 'left'
      });
    </script>
  </body>
</html>


Bootstrap工具提示Tooltips)是Bootstrap框架提供的一个小功能,用于向用户显示一些额外的信息或解释。当用户将鼠标悬停、聚焦或点击某个元素时,工具提示会显示一个文本框,提供有关该元素的更多信息。要使用Bootstrap工具提示,首先需要在HTML文档中包含Bootstrap的CSS和JS文件,以及依赖的Popper.js。 以下是一个简单的Bootstrap工具提示示例: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bootstrap Tooltips Example</title> <!-- 引入Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> </head> <body> <!-- HTML结构 --> <div class="container"> <h3>Bootstrap Tooltips 示例</h3> <!-- data-toggle="tooltip" 用于激活工具提示,title属性包含要显示的文本 --> <button type="button" class="btn btn-secondary" data-toggle="tooltip" title="这是一个工具提示!">悬停查看工具提示</button> </div> <!-- 引入Bootstrap JS 和 Popper.js --> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.9.3/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <script> // 初始化工具提示 $(document).ready(function(){ $('[data-toggle="tooltip"]').tooltip(); }); </script> </body> </html> ``` 在这个例子中,按钮元素上有一个`data-toggle="tooltip"`属性,它告诉Bootstrap框架我们想要一个工具提示。`title`属性包含了要显示的文本内容。当用户将鼠标悬停在按钮上时,工具提示就会显示出来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值