How do I add classes to items in Owl Carousel 2?

后端 未结 2 1838
陌清茗
陌清茗 2020-12-05 08:50

My goal is to make a carousel that looks like this:

\"Carousel\"

In case you don\'t know what you\'re looki

相关标签:
2条回答
  • 2020-12-05 09:21

    add this in your css and js file.

    .owl-carousel.owl-drag .owl-item.center .item {
        background: rgb(25, 0, 255) ;
        transform: scale(1.1)
      }
    
    
    $(document).ready(function () {
    
    $(".owl-carousel").owlCarousel({
        center: true,
        dots: false,
        loop:true,
        responsive: {
            1900: {
                items: 7
            },
            1440: {
                items: 5
            },
            760: {
                items: 3
            },
            0: {
                items: 1
            }
        }
    });
    

    });

    0 讨论(0)
  • 2020-12-05 09:33

    You can do it this way:

    $(function(){
        $('.loop').owlCarousel({
            center: true,
            items:5,
            loop:true,
            margin:10
        });
    
        $('.loop').on('translate.owl.carousel', function(e){
            idx = e.item.index;
            $('.owl-item.big').removeClass('big');
            $('.owl-item.medium').removeClass('medium');
            $('.owl-item').eq(idx).addClass('big');
            $('.owl-item').eq(idx-1).addClass('medium');
            $('.owl-item').eq(idx+1).addClass('medium');
        });
    }); 
    

    Listening to the event of your choice

    List of available events here

    In the demo, I just add the class big to the main item, and the class medium to the previous and next one. From that you can play with whichever css property you want.

    LIVE DEMO


    NOTE:

    You could also just play with plugin classes, .active and .center (or you can also define your own, as you can see here: custom classes

    0 讨论(0)
提交回复
热议问题