Javascript 从小到大猫头鹰旋转木马中心模式

Javascript 从小到大猫头鹰旋转木马中心模式,javascript,jquery,css,owl-carousel,Javascript,Jquery,Css,Owl Carousel,我的目标是制作一个如下所示的旋转木马: 从小到大 如果您不知道自己在看什么,则有5个图像/项目,但只有中间的一个以全尺寸显示。靠近中心的图像更小,外部的图像更小 但实际上,用于实现这一点的owl旋转木马类(medium,big)已经被弃用了 我想知道在我的猫头鹰旋转木马里有没有可能做这样的东西 这是我在年所做工作的链接 请别忘了找钱在我手里 请先发表评论 /** * Plugin for linking multiple owl instances * @version 1.0.0 *

我的目标是制作一个如下所示的旋转木马:

从小到大

如果您不知道自己在看什么,则有5个图像/项目,但只有中间的一个以全尺寸显示。靠近中心的图像更小,外部的图像更小

但实际上,用于实现这一点的owl旋转木马类(
medium
big
)已经被弃用了

我想知道在我的猫头鹰旋转木马里有没有可能做这样的东西

这是我在年所做工作的链接

请别忘了找钱在我手里

请先发表评论

/**
 * Plugin for linking multiple owl instances
 * @version 1.0.0
 * @author David Deutsch
 * @license The MIT License (MIT)
 */
;(function($, window, document, undefined) {
    /**
     * Creates the Linked plugin.
     * @class The Linked Plugin
     * @param {Owl} carousel - The Owl Carousel
     */
    var Linked = function(carousel) {
        /**
         * Reference to the core.
         * @protected
         * @type {Owl}
         */
        this._core = carousel;

        /**
         * All event handlers.
         * @protected
         * @type {Object}
         */
        this._handlers = {
            'dragged.owl.carousel changed.owl.carousel': $.proxy(function(e) {
                if (e.namespace && this._core.settings.linked) {
                    this.update(e);
                }
            }, this),
            'linked.to.owl.carousel': $.proxy(function(e, index, speed, standard, propagate) {
                if (e.namespace && this._core.settings.linked) {
                    this.toSlide(index, speed, propagate);
                }
            }, this)
        };

        // register event handlers
        this._core.$element.on(this._handlers);

        // set default options
        this._core.options = $.extend({}, Linked.Defaults, this._core.options);
    };

    /**
     * Default options.
     * @public
     */
    Linked.Defaults = {
        linked: false
    };

    /**
     * Updated linked instances
     */
    Linked.prototype.update = function(e) {
        this.toSlide( e.relatedTarget.relative(e.item.index) );
    };

    /**
     * Carry out the to.owl.carousel proxy function
     * @param {int} index
     * @param {int} speed
     * @param {bool} propagate
     */
    Linked.prototype.toSlide = function(index, speed, propagate) {
        var id = this._core.$element.attr('id'),
            linked = typeof(this._core.settings.linked) === 'string' ? this._core.settings.linked.split(',') : this._core.settings.linked;

        if ( typeof propagate == 'undefined' ) {
            propagate = true;
        }

        index = index || 0;

        if ( propagate ) {
            $.each(linked, function(i, el){
                $(el).trigger('linked.to.owl.carousel', [index, 300, true, false]);
            });
        } else {
            this._core.$element.trigger('to.owl.carousel', [index, 300, true]);

            if ( this._core.settings.current ) {
                this._core._plugins.current.switchTo(index);
            }
        }
    };

    /**
     * Destroys the plugin.
     * @protected
     */
    Linked.prototype.destroy = function() {
        var handler, property;

        for (handler in this._handlers) {
            this.$element.off(handler, this._handlers[handler]);
        }
        for (property in Object.getOwnPropertyNames(this)) {
            typeof this[property] != 'function' && (this[property] = null);
        }
    };

    $.fn.owlCarousel.Constructor.Plugins.linked = Linked;

})(window.Zepto || window.jQuery, window, document);


$(".carousel_1").owlCarousel({
    nav: false,
    items: 1,
    margin:1,
    linked: ".carousel_2"
});
var sync2 = $(".carousel_2");
$(sync2).owlCarousel({
    nav: true,
    loop:true,
    items: 4,
    margin:10,
    center:true,
    linked: sync2.prev()
}).on('initialized.owl.carousel linked.to.owl.carousel', function() {
    sync2.find('.owl-item.current').removeClass('current');
    var current = sync2.find('.owl-item.active.center').length ? sync2.find('.owl-item.active.center') : sync2.find('.owl-item.active').eq(0);
    current.addClass('current');
});
我试过了

当第一个旋转木马(carousel_1)配置结束时,我尝试添加这部分代码

在那里,我尝试选择第一个和最后一个项目,并给它们类名称,在这个类名称中,我将更改它们的
width
height

但这个解决方案只取第一个和最后一个项目,我需要从左到右到中心的所有项目

同样,在这个解决方案中,没有像那样工作

if(index==1)
而不是数字1。任何索引都可以是。这是向一个元素添加两个类

checkClasses();
$(".carousel_2").on('translated.owl.carousel', function(event) {
    checkClasses();
});

function checkClasses(){
    var total = $('.carousel_2 .owl-stage .owl-item.active').length;

    $('.carousel_2 .owl-stage .owl-item').removeClass('firstActiveItem lastActiveItem');

    $('.carousel_2 .owl-stage .owl-item.active').each(function(index){

        if (index === 0) {
            // this is the first one
        $(this).addClass('firstActiveItem');
        }
        if (index === total - 1 && total>1) {
            // this is the last one
            $(this).addClass('firstActiveItem');
        }

    });
}

CSS中的一段代码就可以了

.owl-carousel .owl-stage {
    max-height: 200px;
    display: flex;
    align-items: center;
}
.carousel_2 .active.center + .active,.carousel_2 .active:first-child,
.carousel_2 :not(.active) + .active{
   height:150px;
}
.carousel_2 .active.center{
   height:200px;
}
.owl-carousel .owl-item img{height:100%}

更新
7
和/或
n
数字项,css将不起作用,但您可以使用jQuery代码,如

$('.h-150px').removeClass('h-150px');
$('.h-200px').removeClass('h-200px');
// add class to just next/prev active element
current.next('.active').addClass('h-150px').end().prev('.active').addClass('h-150px');
// add class to just second next/prev active element
current.next('.active').next('.active').addClass('h-110px').end()
      .end().prev('.active').prev('.active').addClass('h-110px');

我已经与owl carousal合作5个多月了,在owl carousal中我从未见过这样的事情。但我发现了一个你想要的演示。转到carousal标签并检查。这可能会有帮助you@Rameshty寻求帮助,但猫头鹰转盘也有这个方法的链接,你给了我,我没有看到任何东西在那里看起来像在img,我粘贴在链接,你可以在滑块下一些蓝色按钮。在这里,找到carousal选项并单击它。在那里,您可以找到您想要的。它实际上不是您想要的,但通过很少的配置,您可以实现它。谢谢你让我知道猫头鹰carousal能做到