I am trying to create my own vertical image carousel because I cannot use any plugins there due to js events related to the images that I need to save, and the only way that will work for me is to create a regular carousel.
Functionality
- The image carousel has 3 equal sizes in the viewport.
- The image carousel has a next / previous button that allows you to view / select other images.
- The next / previous button allows you to do only one step at a time, that is, it will not select the next set of images and display it in the viewing window.

- The carousel offers you to select any images in the viewport, and this will be synchronized when you click the next / prev button

All of the above functions are already implemented.
PROBLEM
The last image will not snap / pause in front of the next button, as it will create a space between them.

JS code
$(function(){ var image_height = 0; var gallery_offset = 0; var image_count = $('img.thumbnail').length; var click_count = 0; var image_height = 0; var last_images_count = 0; $('.gallery-container a').click(function(){ $('.gallery-container a').removeClass('active') $(this).addClass('active'); }); jQuery('.thumbnail').each(function(){ $(this).on('load', function(){ image_height = $(this).parent().outerHeight(); }); image_height = $(this).parent().outerHeight(); }) // Disable arrows if the images count is 3 below if(image_count <= 3) { $('.product-more-pictures .up, .product-more-pictures .down').addClass('disabled') click_count = 0; } // Set the first image as active jQuery('.gallery-container img.thumbnail').first().click(); var thumb_active = jQuery('.gallery-container .active'); $('.gallery-container a').on('click', function() { thumb_active = jQuery('.gallery-container .active'); }); $('.product-more-pictures .down').on('click', function (e) { $('.product-more-pictures .up').removeClass('disabled') if(thumb_active.nextAll(':lt(1)').length) { thumb_active.nextAll(':lt(1)').children().click() thumb_active = jQuery('.gallery-container .active'); } if( ! thumb_active.next().length) { $(this).addClass('disabled') } else { $(this).removeClass('disabled'); } if (click_count < image_count) { click_count = click_count + 1; update_gallery('down'); } }); $('.product-more-pictures .up').on('click', function () { $('.product-more-pictures .down').removeClass('disabled') if(thumb_active.prevAll(':lt(1)').length) { thumb_active.prevAll(':lt(1)').children().click() thumb_active = jQuery('.gallery-container .active'); } if( ! thumb_active.prev().length) { $(this).addClass('disabled') } else { $(this).removeClass('disabled'); } if (click_count > 0) { click_count = click_count - 1; update_gallery('up'); } }); function update_gallery(direction) { gallery_offset = click_count * image_height; last_images_count = thumb_active.nextAll().length; $(".gallery-container").animate({ 'top': '-' + gallery_offset + 'px' }, 800); } });
Fiddle: https://jsfiddle.net/qrvrdjch/6/
Any help would be greatly appreciated :)
source share