Jurgis Lietunovas Jurgis Lietunovas - 2 months ago 13
jQuery Question

Jquery carousel clicking active item doesnt redirect

I've got a carousel in this webpage https://stfn.herokuapp.com and It works almost perfect, only the main (active) item, which is in the center, Doesn't do anything once it's clicked (it's supposed to redirect) I tried to add the link both in js file and in the index, but didn't solve the problem anyone got tips?

[edit]

Forgot to upload the latest build before asking the question, just did it. So I added an a tag to the img in the index.html, and that doesn't seem to work either. Here's a snippet of code for redirecting from the js file

$('.carousel .item').click(function(e) {
var index = $(this).index('li');
carousel.cycleActiveTo(index);
// song3();
e.preventDefault();

if ( currentIndex != index ){
var difference;

if ( currentIndex == 0 && index >= 5 ){
difference = (index - currentIndex) - 13;
} else {
difference = index - currentIndex;
}

difference = Math.abs(difference);
delay = difference * options.duration;
currentIndex = index;

console.log(delay);

setTimeout( goToLink, delay );
}
});

goToLink = function() {
if (currentIndex == 0) {
// console.log("works:");
document.location.href = "about.html"
}
if (currentIndex == 1) {
document.location.href = "blog.html"
}
else if (currentIndex == 2) {
document.location.href = "collection.html"
}
else if (currentIndex == 3) {
document.location.href = "shop.html"
}
else if (currentIndex == 4) {
// alert("ABOUT2");
document.location.href = "about.html"
}
else if (currentIndex == 5) {
document.location.href = "blog.html"
}
else if (currentIndex == 6) {
document.location.href = "collection.html"
}
else if (currentIndex == 7) {
document.location.href = "contact.html"
}
else if (currentIndex == 8) {
document.location.href = "shop.html"
}
else if (currentIndex == 9) {
document.location.href = "contact.html"
}
else if (currentIndex == 0) {
document.location.href = "about.html"
}
}

});


So as you see, every element has an index assigned to it, and it allows to switch to a specific page. The active item has the index number 0, however it doesn't seem to work like the others

Answer

if ( currentIndex != index ){ <-- this check is false since both are zero.

So if the check is equal it does nothing

You need an else and call the goto method.

if ( currentIndex != index ){ 
   ... the code ...
} else {
    goToLink();
}