Add Play/Pause button to bootstrap carousel

后端 未结 3 1881
孤城傲影
孤城傲影 2020-12-14 03:58

I have read almost all the threads regarding to the bootstrap carousel, but haven\'t found an answer to my question. I have added two control buttons (play/pause) to the car

3条回答
  •  别那么骄傲
    2020-12-14 04:22

    For those who would like the play/pause buttons to switch off. jsFiddle example

    Javascript:

     $("button").click(function() {
      if ($(this).attr("id") === "pauseButton") {
        $('#homeCarousel').carousel('pause');
        $(this).attr("id", "playButton");
        $("span", this).toggleClass("glyphicon-play glyphicon-pause");
      } else {
        $('#homeCarousel').carousel('cycle');
        $(this).attr("id", "pauseButton");
        $("span", this).toggleClass("glyphicon-pause glyphicon-play");
      }
    });
    

    HTML:

提交回复
热议问题