I use jcarousel lite to display a startup logo carousel on one of my sites. I tried to make it responsive (maximum 6 images on the largest display) using the following javascript. The carousel works great using source code without trying to change the number of images.
<script> function carouselLogic(){ if ($(window).width() > 959 ){ visible = 6; changeCarousel(visible); } else if($(window).width() > 767){ visible = 4; changeCarousel(visible); } else if($(window).width() > 599){ visible = 2; changeCarousel(visible); } } carouselLogic(); $(window).resize(function(){ carouselLogic(); }); function changeCarousel(visible){ $(".logoCarousel").jCarouselLite({ auto: 2500, speed: 1000, visible: visible }); } </script>
Images are displayed in a line with an edge of 20 pixels left / right.
This code should change the visible number of logos to ensure that they still fit on the page with each change.
As a result, the carousel automatically scrolls. It bounces back and forth throughout the place and is much faster than the default.
Any suggestions for improving this code?
source share