Reputation: 306
I am trying to create custom carousel with thumbnails
. I have 2 buttons(left and right arrows)
, which must simulate clicks on thumbnails. Created this code, but I want to show previous image on the left click, no matter how many times I clicked on the right arrow.
var clicks= 0;
$('#rightarrow').on('click', function(){
clicks += 1;
$( ".thumbnail").eq(clicks).trigger("click");
})
var leftClicks = $('.thumbnail').length;
$('#leftarrow').on('click', function(){
leftClicks -= 1;
$( ".thumbnail").eq(leftClicks).trigger("click");
})
Upvotes: 0
Views: 103
Reputation: 50
Try to use the clicks variable instead of leftClicks
$('#leftarrow').on('click', function(){
clicks -= 1;
$( ".thumbnail").eq(clicks).trigger("click");
})
Upvotes: 1