-1

i'm trying to use jCarousel but I need to remove the prev control when the carousel hits the first item of the list.

I tried (view fiddle) but it only happens when I click one time more on prev control.

Here is the fiddle:

Preview

Carol
  • 329
  • 3
  • 16

1 Answers1

2

That's because it takes 100 milliseconds to run the sliding animation, and the if statement is being run at the beginning, when the CSS top property has -60 px.

If you set a timeout call, it will work fine:

$('a.glist-prev').click(function () {
    setTimeout(function(){
        if (parseInt($('ul.ganhadores-list').css('top')) === 0) {
            $('a.glist-prev').addClass('disabled');
        }        
    },200);
});

http://jsfiddle.net/wDu6Z/

Update: My answer is related to the reason why your code doesn't work. It's not an implementation. You can find a proper example on the official website.

(function($) {
    $(function() {
        $('.jcarousel').jcarousel();

        $('.jcarousel-control-prev')
            .on('jcarouselcontrol:active', function() {
                $(this).removeClass('inactive');
            })
            .on('jcarouselcontrol:inactive', function() {
                $(this).addClass('inactive');
            })
            .jcarouselControl({
                target: '-=1'
            });

        $('.jcarousel-control-next')
            .on('jcarouselcontrol:active', function() {
                $(this).removeClass('inactive');
            })
            .on('jcarouselcontrol:inactive', function() {
                $(this).addClass('inactive');
            })
            .jcarouselControl({
                target: '+=1'
            });
    });
})(jQuery);
Sebastian
  • 2,154
  • 1
  • 26
  • 42