bootstrap carousel hide controls on first and last

前端 未结 4 2280
长情又很酷
长情又很酷 2020-12-06 13:51

How can I hide the left control if the carousel is on the first item, and how can I hide the right control when the carousel is on the last item.

My code below hides

4条回答
  •  误落风尘
    2020-12-06 14:37

    IF YOU'RE USING BOOTSTRAP 3:

    The event is 'slid.bs.carousel' not 'slid'

    $('.carousel').carousel({
        interval: false,
    })
    
    $(document).ready(function () {               // on document ready
        checkitem();
    });
    
    $('#myCarousel').on('slid.bs.carousel', checkitem);
    
    function checkitem()                        // check function
    {
        var $this = $('#myCarousel');
        if ($('.carousel-inner .item:first').hasClass('active')) {
            $this.children('.left.carousel-control').hide();
        } else if ($('.carousel-inner .item:last').hasClass('active')) {
            $this.children('.right.carousel-control').hide();
        } else {
            $this.children('.carousel-control').show();
    
        }
    }
    

提交回复
热议问题