Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery jCarousel with paging dots?

I was using jCarousel plugin to display a series of items. I was following this example from the web site to get external controls and a paging control.

There's two problems with this approach:

  1. i need to add the items for the numbers manually (instead of just calculating the number of items in the carousel with JS), although I can live with this, and

  2. There seems to be no way to highlight (via a class change) the item for the current slide

What I am doing is using bullets as paging dots, as you can see in this fiddle

<div class="carousel-nav cf">
<table>
<tr>
    <td><a href="#" id="mycarousel-prev">&#x25C0;</a></td>
    <td>
        <div class="jcarousel-control">
          <a href="#">&bull;</a>
          <a href="#">&bull;</a>
          <a href="#">&bull;</a>
        </div>
    </td>
    <td><a href="#" id="mycarousel-next">&#x25BA;</a></td>
</tr>
</table>
</div>

and would like to set the class to "active" or similar for the current item.

Any ideas? Or is there a better plugin for this? I tried Cycle but I need two have 2 or more items showing at once. Thanks.

like image 985
Steve Avatar asked Jan 16 '26 20:01

Steve


1 Answers

html:

<ul class="jcarousel-control"></ul>

script:

 $('.jcarousel-control')
        .on('jcarouselpagination:active', 'li', function() {
            $(this).addClass('active');
        })
        .on('jcarouselpagination:inactive', 'li', function() {
            $(this).removeClass('active');
        })
        .jcarouselPagination({
            'perPage':1,
            'item': function(page, carouselItems) {
                return '<li class="' + (page == 1 ? "active" : "") + '"><a href="#' + page + '"></a></li>';
            }
        });

    $('.mycarousel-prev').jcarouselControl({target:'-=1'});
    $('.mycarousel-next').jcarouselControl({target:'+=1'});
like image 138
gokhan Avatar answered Jan 19 '26 14:01

gokhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!