bootstrap-js元件-輪播效果
阿新 • • 發佈:2019-01-23
簡單的沒有控制的圖片輪播:
<div class="carousel slide" data-ride="carousel" id="mycarousel">
<!-- 幻燈片圖片 -->
<div class="carousel-inner">
<div class="item active">
<img src="images/lunbo1.jpg">
</div >
<div class="item">
<img src="images/lunbo2.jpg">
</div>
<div class="item">
<img src="images/lunbo3.jpg">
</div>
</div >
</div>
完整的輪播:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="css/bootstrap.css" >
<script src="js/jquery.1.12.4.min.js"></script>
<script src="js/bootstrap.js"></script>
<title>Bootstrap</title>
</head>
<style type="text/css">
*{
font-family: 微軟雅黑;
}
</style>
<body>
<div class="container">
<h1 class="page-header">BootStrap</h1>
<div class="carousel slide" data-ride="carousel" id="mycarousel">
<!-- 幻燈片圖片 -->
<div class="carousel-inner">
<div class="item active">
<img src="images/lunbo1.jpg">
</div>
<div class="item">
<img src="images/lunbo2.jpg">
</div>
<div class="item">
<img src="images/lunbo3.jpg">
</div>
</div>
<!-- 指示燈效果 -->
<ol class="carousel-indicators">
<li data-target="#mycarousel" data-slide-to="0" class="active"></li>
<li data-target="#mycarousel" data-slide-to="1"></li>
<li data-target="#mycarousel" data-slide-to="2"></li>
</ol>
<!-- 左右控制 -->
<a href="#mycarousel" class="left carousel-control" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a href="#mycarousel" class="right carousel-control" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</body>
<script
</html>
新增圖片說明;
<div class="carousel slide" data-ride="carousel" id="mycarousel">
<!-- 幻燈片圖片 -->
<div class="carousel-inner">
<div class="item active">
<img src="images/lunbo1.jpg">
<div class="carousel-caption">
<h3>The one slide</h3>
<p>live off obstetrician </p>
</div>
</div>
<div class="item">
<img src="images/lunbo2.jpg">
<div class="carousel-caption">
<h3>The two slide</h3>
<p>live off obstetrician </p>
</div>
</div>
<div class="item">
<img src="images/lunbo3.jpg">
<div class="carousel-caption">
<h3>The three slide</h3>
<p>live off obstetrician </p>
</div>
</div>
</div>
<!-- 左右控制 -->
<a href="#mycarousel" class="left carousel-control" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a href="#mycarousel" class="right carousel-control" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
css:
.carousel-caption{
background: #000;
opacity: 0.6;
width: 100%;
left: 0px!important;
bottom: 0px;
height: 100px;
}
新聞介面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/jquery.1.12.4.min.js"></script>
<script src="js/bootstrap.js"></script>
<title>Bootstrap</title>
</head>
<style type="text/css">
*{
font-family: 微軟雅黑;
}
.carousel-caption{
background: #000;
opacity: 0.6;
width: 100%;
left: 0px!important;
bottom: 0px;
height: 100px;
}
</style>
<body>
<div class="container">
<h1 class="page-header">BootStrap</h1>
<div class="carousel slide" data-ride="carousel" id="mycarousel">
<!-- 幻燈片圖片 -->
<div class="carousel-inner">
<div class="item active">
<img src="images/lunbo1.jpg">
<div class="carousel-caption">
<h3>The one slide</h3>
<p>live off obstetrician </p>
</div>
</div>
<div class="item">
<img src="images/lunbo2.jpg">
<div class="carousel-caption">
<h3>The two slide</h3>
<p>live off obstetrician </p>
</div>
</div>
<div class="item">
<img src="images/lunbo3.jpg">
<div class="carousel-caption">
<h3>The three slide</h3>
<p>live off obstetrician </p>
</div>
</div>
</div>
<!-- 左右控制 -->
<a href="#mycarousel" class="left carousel-control" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a href="#mycarousel" class="right carousel-control" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</body>
<script>
$('.carousel-caption').hide();
$('.item').hover(
function(){
$(this).find('.carousel-caption').slideDown();
},
function(){
$(this).find('.carousel-caption').slideUp();
},
);
</script>
</html>