Data-interval in carousel function is used to set the time to slide images
We can set the data-interval by using data-attribute and javascript
In this example we had used data-interval to set the time by using data-attributes
<style> .carousel-inner > .item > img, .carousel-inner > .item > a > img { width: 70%; margin: auto; } </style> </head> <body> <div class="container"> <h2>Carousel with data interval using data-attribute </h2> <p></p> <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="500"> <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="mango.jpg" height="200" width="200" /> </div> <div class="item"> <img src="download.jpg" height="200" width="200" /> </div> <div class="item"> <img src="Gauva.jpg" height="200" width="200" /> </div> <div class="item"> <img src="pomogranite.jpg" height="200" width="200" /> </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>
data-interval
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, 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 slide the image by setting data-interval using javascript
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<h2>Carousel using data-interval with javascript</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.jpg" height="200" width="100"/>
</div>
<div class="item">
<img src="images%20(1).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});
$(".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>
Data-interval using javascript
container
and we have another div with id as mycarouse
l
and class value as carousel slide
and we have defined the <ol>
element to define the list values with class values as itemcarousel-inner
to define the images with respective height and widthleft
and right
carousel controls which are used as symbols for turning the images with anchor tag with class value as left carousel control
and right carousel control
#mycarousel
, with data-interval
as 500 which sets the time for the images to slide and we have called the list items with values item numbersoutput
Views: 24096 | Post Order: 42