Bootstrap Carousel With Play Pause
Bootstrap Carousel With Play Pause options
HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<div class="container">
<br>
<button id="toggleCarousel"><i class="fa fa-pause"></i></button>
<div id="myCarousel" class="carousel slide">
<!-- Indicators -->
<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>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<div class="img-title">Chania This is an Image</div>
<img src="http://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" width="460" height="345">
</div>
<div class="item">
<div class="img-title">Some other text discription goes at the top that goes a distance across the top</div>
<img src="http://www.w3schools.com/bootstrap/img_chania2.jpg" alt="Chania" width="460" height="345">
</div>
<div class="item">
<div class="img-title">an Image of Flower</div>
<img src="http://www.w3schools.com/bootstrap/img_flower.jpg" alt="Flower" width="460" height="345">
</div>
<div class="item">
<div class="img-title">Keep this to the Description</div>
<img src="http://www.w3schools.com/bootstrap/img_flower2.jpg" alt="Flower" width="460" height="345">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon...
CSS
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 100%;
margin: auto;
}
.img-title {
position: relative;
background-color: #fff;
color: #000;
width: 100%;
text-align: center;
opacity: 0.43;
filter: alpha(opacity=43);
}
JavaScript
$(function() {
/* Initialize Carousel */
var paused = 0;
$('#myCarousel').carousel({
pause: 0
});
/* Play trigger */
$('#toggleCarousel').click(function() {
var state = (paused) ? 'cycle' : 'pause';
paused = (paused) ? 0 : 1;
$('#myCarousel').carousel(state);
$('#myCarousel').carousel(1000);
$(this).find('i').toggleClass('fa-play fa-pause');
});
});