Bootstarp4 pop-up box

Pop-up box control is similar to the prompt box that displays after a mouse click to the elements, and the prompt box is different is that it can display more content.

1: Creating a pop-up box

To create a pop-up box by adding elements to the data-toggle = "popover". 

content of the title property of the pop-up box header, data-content display attribute of the popup text:

 Note: The  pop-up box will write the initialization code jQuery's: then call on the specified elements  popover () method.

 The following examples may be used anywhere in the pop-up box in the document:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h3>弹出框实例</h3>
  <a href="#" data-toggle="popover"= "pop-up box content"Data-Content= "pop-up box titled"title>多次点我</a>
</div>

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover();   
});
</script>

</body>
</html>

2: Specify the location of the pop-up box

Pop-up box element displayed on the right by default. 

Direction may be used to set the attribute data-placement popup display: top, bottom, left or right:
<div class="container">
  <h3>弹出框实例</h3> <br><br><br><br><br><br>
  <a href="#" title="Header" data-toggle="popover" data-placement="top" data-content="Content">点我</a>
  <a href="#" title="Header" data-toggle="popover" data-placement="bottom" data-content="Content">点我</a>
  <a href="#" title="Header" data-toggle="popover" data-placement="left" data-content="Content">点我</a>
  <a href="#" title="Header" data-toggle="popover" data-placement="right" data-content="Content">点我</a>
</div>

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover();   
});
</script>

3:关闭弹出框

默认情况下,弹出框在再次点击指定元素后就会关闭,你可以使用 data-trigger="focus" 属性来设置在鼠标点击元素外部区域来关闭弹出框:
<div class="container">
  <h3>弹出框实例</h3> <br>
  <a href="#" title="取消弹出框" data-toggle="popover" data-trigger="focus" data-content="点击文档的其他地方关闭我">点我</a>
</div>

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover();   
});
</script>

 

提示:如果你想实现在鼠标移动到元素上显示,移除后消失的效果,可以使用 data-trigger 属性,并设置值为 "hover":

<div class="container">
  <h3>弹出框实例</h3> <br>
  <a href="#" title="Header" data-toggle="popover" data-trigger="hover" data-content="一些内容">鼠标移动到我这</a>
</div>

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover();   
});
</script>

 

Guess you like

Origin www.cnblogs.com/gjh99/p/11280782.html