I have implemented a standard Bootstrap carousel in my project:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<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">
<div class="carousel-caption">
<h1>App Preview</h1>
</div>
</div>
<div class="item">
<div class="carousel-caption">
<h1>Contact Details</h1>
</div>
</div>
<div class="item">
<div class="carousel-caption">
<h1>Choose plan</h1>
</div>
</div>
<div class="item">
4
</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>
I am attempting to modify the behavior of the 'previous' and 'next' buttons on the carousel based on the user's position. Here is the JavaScript I am using:
$('.carousel').carousel.on('slid', '', function () {
var $this = $(this);
$this.children('.carousel-control').show();
if ($('.carousel-inner .item:first').hasClass('active')) {
$this.children('.left.carousel-control').hide();
} else if ($('.carousel-inner .item:last').hasClass('active')) {
$this.children('.right.carousel-control').hide();
}
});
However, I am encountering an error stating 'carousel.on is not a function'. The jQuery library is included at the top of my ASP.NET MVC page along with the Bootstrap file:
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>