//Keep values in a closure as the other carousel indexes were getting mixed with this one
(function () {
var current = 0;
var nextImage = 0;
var container = $('.double-image-gallery-carousel-container');
var size = container.find('.row[data-csIndex]').length - 1;
$('.image-gallery-carousel-container .arrow-row a').on('click', function (e) {
e.preventDefault();
//no need to do anything if gallery size is less than 1
if (size <= 1) {
return;
}
//hide current image
container.find('[data-csIndex="' + current + '"]').toggleClass('d-flex d-none');
//next
if ($(this).hasClass("arrow-right")) {
if (current === size) {
nextImage = 0;
current = 0;
} else {
current++;
nextImage++;
}
}
//prev
if ($(this).hasClass("arrow-left")) {
if (current === 0) {
nextImage = size;
current = size;
} else {
current--;
nextImage--;
}
}
//show next image
container.find('[data-csIndex="' + nextImage + '"]').toggleClass('d-none d-flex');
//Testing / Debug
//console.log(current + ' of ' + size);
//console.log(prev, current, next);
//scroll into view
var scrollTop = $(window).scrollTop();
var oldHeight = $(this).closest('.image-gallery-carousel-container').height();
if ($(this).hasClass('arrow-mobile')) {
var newHeight = $(this).closest('.image-gallery-carousel-container').height();
window.scrollTo(0, scrollTop + newHeight - oldHeight)
}
});
})();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.