jCarousel ajax加载下一个按钮

时间:2015-04-10 13:19:13

标签: javascript jquery ajax jcarousel

我正在使用jcarousel从单独的滑块中加载多个单词的搜索结果 当我点击下一个按钮时,我的滑块会添加6个元素,但滑块不会滚动,直到再次点击为止 问题在哪里?

var runSearchCarousel = function(){
        var carousel = jQuery('.row-wrap').jcarousel({vertical: false, animation: 'fast', visible: 4, wrap: 'last'});
        return carousel;
    };

var searchCarouselMore = function(){

    jQuery('.search-row').on('click', '.next-b', function(){

        var $this = jQuery(this),
        id = $this.attr('id').substring('rightArrow-'.length),
        container = jQuery('#slider_' + id),
        containerPosition = container.parent().parent().find('#rowPosition-' + id).val(),
        lastLi = container.find('li.gridWrap').filter(':last'),
        carousel = container.parent(),
        lastSku = lastLi.attr('id').substring('product-'.length);

        $this.jcarouselControl({
            carousel : carousel,
            target : '+=4'
        });


        jQuery.ajax({
            type: 'get',
            url : '/ajax/_fetchMultiSearch.php',
            data: {
                toFetch: 6,
                containerPosition: containerPosition,
                lastSku: lastSku
            },
            cache: false,
            success: function(response){
                container.append(response);
                uiResize();
                carousel.jcarousel('reload');
            }
        });

    });

1 个答案:

答案 0 :(得分:0)

解决

var runSearchCarousel = function(){
    var carousel = jQuery('.row-wrap').jcarousel({vertical: false, animation: 'slow', visible: 4});
    return carousel;
};

var searchCarouselMore = function(){
    jQuery(".prev-b").on("jcarouselcontrol:active", function() {
        jQuery(this).removeClass("inactive")
    }).on("jcarouselcontrol:inactive", function() {
        jQuery(this).addClass("inactive")
    }).jcarouselControl({
        target: "-=1"
    });

    jQuery(".next-b").on("jcarouselcontrol:active", function() {
        jQuery(this).removeClass("inactive")
    }).on("jcarouselcontrol:inactive", function() {
        jQuery(this).addClass("inactive")
    }).jcarouselControl({
        target: "+=1"
    }); 

    jQuery('.search-row').on('click', '.next-b', function(){

        var $this = jQuery(this),
        id = $this.attr('id').substring('rightArrow-'.length),
        container = jQuery('#slider_' + id),
        containerPosition = container.parent().parent().find('#rowPosition-' + id).val(),
        lastLi = container.find('li.gridWrap').filter(':last'),
        carousel = container.parent(),
        lastSku = lastLi.attr('id').substring('product-'.length);

        $this.jcarouselControl({
            carousel : carousel,
            target : '+=4'
        });


        jQuery.ajax({
            type: 'get',
            url : '/ajax/_fetchMultiSearch.php',
            data: {
                toFetch: 6,
                containerPosition: containerPosition,
                lastSku: lastSku
            },
            cache: false,
            success: function(response){
                container.append(response);
                uiResize();
                carousel.jcarousel('reload');
            }
        });

    });

    jQuery('.search-row').on('click', '.prev-b', function(){

        var $this = jQuery(this),
        id = $this.attr('id').substring('leftArrow-'.length),
        container = jQuery('#slider_' + id),
        carousel = container.parent();

        jQuery(this).jcarouselControl({
            carousel : carousel,
            target : '-=4'
        });
    });

};