1
This js is all part of next,Prev and auto of my slide, but there is a "however": when I click on Prev, it comes back and then advances in the same action.
What is wrong with the logic of 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>
pq has a $(Document). ready() inside another?
– Tobias Mesquita
What is the
carousel
what are you using? it has no methods to change the images without having to do it by hand?– Sergio
Yes, but I want the controllers to have a background when the image passes, it’s like an active.. but I’m not getting a background...
– Alexandre
I don’t know much about jquery, I tried to adapt, but I guess it didn’t really matter.. Something about what I’m trying to do.. http://imgur.com/XwZqyqA
– Alexandre
Hello, put your code on the site www.bootply.com, so we can help you better
– Wilson Rosa Gomes