how add spaces between owl carousel item

后端 未结 8 1006
醉酒成梦
醉酒成梦 2021-02-14 16:15

How can i add space between owl item. add margin or padding between items. this is need to be responsive.can i add some gutter in to the jquery.

8条回答
  •  隐瞒了意图╮
    2021-02-14 16:27

    I found the solution. But I had to change source code. I added new option "padding" into $.fn.owlCarousel.options{}. Then I changed formula in calculateWidth : function () {}

    calculateWidth : function () {
        var base = this;
        base.itemWidth = Math.round( (base.$elem.width() + base.options.padding) / base.options.items);
        console.log(base.$owlItems.width());
    },
    

    And last thing, I added this padding (padding-right) for items:

    appendItemsSizes : function () {
            var base = this,
                roundPages = 0,
                lastItem = base.itemsAmount - base.options.items;
    
            base.$owlItems.each(function (index) {
                var $this = $(this);
                $this
                    .css({
                        "width": base.itemWidth,
                        "padding-right": base.options.padding
                    })
                    .data("owl-item", Number(index));
    
                if (index % base.options.items === 0 || index === lastItem) {
                    if (!(index > lastItem)) {
                        roundPages += 1;
                    }
                }
                $this.data("owl-roundPages", roundPages);
            });
        },
    

    So now I can just initialize carousel with option "padding" like this:

    $(".carousel").owlCarousel({
        items : 3,
        padding : 23
    });
    

    And get this result:

提交回复
热议问题