bootstrap carousel hide controls on first and last

前端 未结 4 2298
长情又很酷
长情又很酷 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:33

    The below code is an updated version of TheLittlePig's code for Bootstrap 3 that works both for multiple carousels on the same page and for indicator actions. The explained code is here

    checkitem = function() {
      var $this;
      $this = $("#slideshow");
      if ($("#slideshow .carousel-inner .item:first").hasClass("active")) {
        $this.children(".left").hide();
        $this.children(".right").show();
      } else if ($("#slideshow .carousel-inner .item:last").hasClass("active")) {
        $this.children(".right").hide();
        $this.children(".left").show();
      } else {
        $this.children(".carousel-control").show();
      }
    };
    
    checkitem();
    
    $("#slideshow").on("slid.bs.carousel", "", checkitem);
    

提交回复
热议问题