SSilence / simple.carousel

This is a simple jQuery plugin for creating sliding carousels.
52 stars 40 forks source link

Prev button bug if visible is multiple of li's #3

Open kevinch opened 11 years ago

kevinch commented 11 years ago

I've noticed on the simple red demo and also on my current dev that if you set the 'visible' parameter to 4, for example, and put 12 items in the ul, then if you press the 'prev' button, it'll go to the end of the carousel right after the last item and show nothing. Same if you set 'visible' to 3 and display 6 or 9 items, prev goes to some white space.

TuniLame commented 11 years ago

Hello, I have the same problem here. Did you resolve it?

kevinch commented 11 years ago

Yes with some css/js of my own. But i didn't change the plugin original files. For the css i just set the left arrow to a display:none. Here's the javascript (jQuery based):

var countbook = Math.ceil(($('ul.lookbook li').length)/3),
    aa = 1;

$('.lookbook .next').on('click', function(){
    aa++;
    if(aa >= 2){ $('.lookbook .prev').show(); } 
    if (aa == (countbook)) { $('.lookbook .next').hide(); }
});

$('.lookbook .prev').on('click', function(){
    aa--;
    if(aa == 1){ $('.lookbook .prev').hide(); } 
    if (aa < (countbook)) { $('.lookbook .next').show(); }
});

As you can see, i divide the number of items var the countbook variable by 3 on the first line. This is because i'm dispalying 3 images at a time in the slider. Feel free to update.

TuniLame commented 11 years ago

Hello, Thanks for your asnwer, that resolved my problem :)

kfedotov commented 11 years ago

There's this line of code in the plugin: if (config.current < 0) config.current = (config.visible == 1) ? config.items - 1 : config.items - config.visible + (config.visible - (config.items % config.visible)); Changing it to the following solved it for me: if (config.current < 0) config.current = (config.visible == 1) ? config.items - 1 : config.items - 2 * config.visible + (config.visible - (config.items % config.visible));