ryrych / rcarousel

yet another jQuery UI carousel
http://ryrych.github.com/rcarousel/
171 stars 48 forks source link

number of elements dynamic #37

Closed ursoforte closed 12 years ago

ursoforte commented 12 years ago

in reading

Remember that number of elements you add to a carousel have to be at least number of elements you specify in ‘visible’ option! Otherwise the carousel will not run."

Need to create a "trigger" for the thumbnail images become visible. For when eses are inserted dynamically.

$(document).ready(function(){

            count = $( "#carousel a" ).length;
            total = 1;

            if ( count == 2)
            {
                total = 2;
            }
            else if ( count >= 3)
            {
                total = 3;
            } 

           $( "#carousel" ).rcarousel({
                visible: total,
                step: 1,
                margin:10,                                             
                width: 100,
                height: 100                
            });
});

This is not a bug, it was quickly found to solve my problem. does it have a better way to solve? new feature maybe. I hope this is helpful if someone passes by it.

ryrych commented 12 years ago

I think that you solved it perfectly. There’s not need to have it as a feature since it’s very specific case.

badconker commented 12 years ago

Thanks for this post, i missed this line on the documentation ... ^^' I think we can optimize your "trigger" :

$(document).ready(function(){

    var total = $("#carousel").children().length;
    var visible = 3;
    if(total<visible){
        visible = total;
    }

    $( "#carousel" ).rcarousel({
        visible: visible,
        step: 1,
        margin:10,                                             
        width: 100,
        height: 100                
    });
});