We can make the function pause using data attributes and javascript, pause function makes the sliding images stop when the hover is placed on the images.
We can set the function pause using data-pause="Hover", pause function makes the sliding images stop when the hover is placed on the images.
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<h2>Bootstrap </h2>
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
<li class="item1 active"></li>
<li class="item2"></li>
<li class="item3"></li>
<li class="item4"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="apple-01.jpg" height="200" width="100" />
</div>
<div class="item">
<img src="download.jpg" height="200" width="100" />
</div>
<div class="item">
<img src="images%20(1).jpg" height="200" width="100" />
</div>
<div class="item">
<img src="images.jpg" height="200" width="100" />
</div>
</div>
<a class="left carousel-control" href="#myCarousel" role="button">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<script>
$(document).ready(function () {
$("#myCarousel").carousel({ interval: 500, pause: "hover" });
$(".item1").click(function () {
$("#myCarousel").carousel(0);
});
$(".item2").click(function () {
$("#myCarousel").carousel(1);
});
$(".item3").click(function () {
$("#myCarousel").carousel(2);
});
$(".item4").click(function () {
$("#myCarousel").carousel(3);
});
$(".left").click(function () {
$("#myCarousel").carousel("prev");
});
$(".right").click(function () {
$("#myCarousel").carousel("next");
});
});
</script>
</body>
interval
and pause as hover
to slide in the given time , we use data-interval to slide the image in given time intervalcontainer
and we have another div section in the same div section with class value carousel slide and id as #mycarousel
, data-ride
as carousel which is used to activate the carousel and data-interval
value as 500, and pause as hover we have defined the list values using <ol>
elements with class value carousel-indicators
using list values data-target #mycarousel
and data-slide-to
slides the given slidecarousel-inner
to define the images to slide the images by using div section with class value itemoutput
We can use data-attibute to make function pause, pause function makes the sliding images stop when the hover is placed on the images
<style> .carousel-inner > .item > img, .carousel-inner > .item > a > img { width: 70%; margin: auto; } </style> </head> <body> <div class="container"> <h2>Carousel pause function using data-attributre</h2> <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="500" data-pause="hover"> <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> <div class="carousel-inner" role="listbox"> <div class="item active"> <img src="apple-01.jpg" height="200" width="100"/> </div> <div class="item"> <img src="download.jpg" height="200" width="100"/> </div> <div class="item"> <img src="images%20(1).jpg" height="200" width="100"/> </div> <div class="item"> <img src="images.jpg" height="200" width="100"/> </div> </div> <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> </body>
Pause function with data-attribute
data-attribut
e
as data-pause as Hover
container
and we have defined the div with id as mycarousel
and class value as carousel slide
, data-pause
as hover<ol>
element to define the list values using class value class-indicators
carousel-inner
to define the images left carousel and right carousel
output
Views: 16937 | Post Order: 36