This js is all part of the next, prev and auto of my slide, but there is a "but": when I click on prev, it returns and then advances in the same action.
What's wrong with the logic in this script?
JS:
$(document).ready( function() {
$('#myCarousel').carousel({
interval: 4000
});
var clickEvent = false;
$('#myCarousel').on('click', '.nav a', function() {
clickEvent = true;
$('.nav li').removeClass('active');
$(this).parent().addClass('active');
}).on('slid.bs.carousel', function(e) {
if(!clickEvent) {
var count = $('.nav').children().length -1;
var current = $('.nav li.active');
current.removeClass('active').next().addClass('active');
var id = parseInt(current.data('slide-to'));
if(count == id) {
$('.nav li').first().addClass('active');
}
}
clickEvent = false;
});
$(document).ready(function(){
$(".prev-slide").click(function(){
var count = $('.nav').children().length -1;
var current = $('.nav li.active');
current.removeClass('active').prev().addClass('active');
var id = parseInt(current.data('slide-to'));
});
});
});
HTML:
<ul class="nav nav-pills nav-justified">
<li data-target="#myCarousel" data-slide-to="0" class="active"><a href="#">INTERCAMBIO</a></li>
<li data-target="#myCarousel" data-slide-to="1"><a href="#">AÉREO</a></li>
<li data-target="#myCarousel" data-slide-to="2"><a href="#">PHENOMENAL</a></li>
<li data-target="#myCarousel" data-slide-to="3"><a href="#">CURSOS</a></li>
</ul>