jsor / jcarousel

Riding carousels with jQuery.
https://sorgalla.com/jcarousel/
MIT License
1.99k stars 736 forks source link

disable click event jcarousel pagination element #659

Closed space-ghost closed 10 years ago

space-ghost commented 10 years ago

Hello I want to be able to disable the click event on certain pagination elements so they will in effect kill the ability to scroll to those pages entirely.

My attempts to capture the click and stop propagation have all failed, carousel scrolls no matter what. Any advice on how to disable pagination elements?

jsor commented 10 years ago

A possible solution would be:

$('.jcarouselpagination').jcarouselPagination({
    event: 'myfakeclick',
    item: function(page) {
        return $('<a href="#' + page + '">' + page + '</a>').click(function() {
            // This disables clicks on pagination element 2
            if (parseFloat(page) === 2) {
                return;
            }

            $(this).trigger('myfakeclick');
        });
    }
});

We let the plugin bind to myfakeclick and trigger this event ourself. In this way we can control the triggering.