欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

boostrap笔记(轮播、提示框、弹出框、模态框)

程序员文章站 2022-05-31 11:46:37
...
<!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.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  <style>
  /* Make the image fully responsive */
  .carousel-inner img {
      width: 100%;
      height: 100%;
  }
  </style>
</head>
<body>

<div id="demo" class="carousel slide" data-ride="carousel">
 
  <!-- 指示符 -->
  <ul class="carousel-indicators">
    <li data-target="#demo" data-slide-to="0" class="active"></li>
    <li data-target="#demo" data-slide-to="1"></li>
    <li data-target="#demo" data-slide-to="2"></li>
  </ul>
 
  <!-- 轮播图片 -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="http://static.runoob.com/images/mix/img_fjords_wide.jpg">
	  <div class="carousel-caption">
		  <h1>添加文字描述</h1>
		  <p>文字描述</p>
	  </div>	  
    </div>
    <div class="carousel-item">
      <img src="http://static.runoob.com/images/mix/img_nature_wide.jpg">
    </div>
    <div class="carousel-item">
      <img src="http://static.runoob.com/images/mix/img_mountains_wide.jpg">
    </div>
  </div>
 
  <!-- 左右切换按钮 -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#demo" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a> 
</div>
<br>
  <h3>提示框实例</h3>
  <a href="#" data-toggle="tooltip" data-placement="bottom" title="我是提示内容!">鼠标移动到这</a>
	<br>
  <a href="#" data-toggle="popover" data-placement="right" title="弹出标题" data-content="弹出内容!">鼠标点击这里</a>	
<br><br>	
<div>
	<h1>模态框实例</h1>
	<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Mymodal">
	打开模态框:
	</button>
	
	<div class="modal fade" id="Mymodal">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				
				<div class="modal-header">
					<h4 class="modal-title">模态框头部</h4>
					<button type="button" class="close" data-dismiss="modal">&times</button>
				</div>	
				
				<div class="modal-body">
					模态框内容..
				</div>	
				
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
				</div>	
				
			</div>
		</div>
	</div>	
</div>	

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

boostrap笔记(轮播、提示框、弹出框、模态框)

boostrap笔记(轮播、提示框、弹出框、模态框)

 

boostrap笔记(轮播、提示框、弹出框、模态框)

用bootstrap实现图片轮播比原生js/css实现代码更简洁,逻辑更清楚

carrousel-caption:添加文字描述

data-placement:指定弹出框位置

data-toggle="tooltip" :创建提示框

data-toggle="popover":创建弹出框

title :弹出框的标题

data-content:弹出框的文本内容

弹出框要写在 jQuery 的初始化代码里: 然后在指定的元素上调用 popover() 方法。

data-trigger="focus" :设置在鼠标点击元素外部区域来关闭弹出框

data-trigger="hover":实现在鼠标移动到元素上显示,移除后消失的效果