I've been working on making a basic little image carousel in jQuery.
Currently at the moment I am stuck on the if else
logic inside of my changeImage
function.
When the user clicks on the "next" link then the next image in line should fade in. Luckily when I comment out the if else
statement I'm able to achieve the images fading out but this is not what I am after. So we know it's a logic issue.
I'm just not sure how to implement the correct syntax with combining conditions
within my if else
statement and I'm sure this logic could also be much cleaner.
Please review
function changeImage (newIndex) {
var i = newIndex;
var current = i;
// `if` user clicks on next then slide image "right"
// something wrong here with my logic..
if ((newIndex === 'next') && i === (current < lengthOfImages - 1)) {
return current + 1;
}
else {
return 0;
}
// fadeout
listOfImages.fadeOut(transitionSpeed).
eq(i).fadeIn(transitionSpeed);
}
// click function on the next link
$('.next').on('click',function() {
changeImage('next');
});
Some feed back on how to fix this with a few hints towards a solution would be greatly appreciated.