Skip to content Skip to sidebar Skip to footer

Bootstrap Carousel: Disable Indicators

How to make carousel-indicators not clickable on mobile? So that when I click on them on mobile devices, slides don't change. I am using latest bootstrap.

Solution 1:

Let's change the appearance of the standard example for small screens.


1. Indicators can be hidden

Add class hidden-xs to <ol class="carousel-indicators">.

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

.carousel-inner > .item > img {
  width: 100%;
}
<divid="carousel-example-generic"class="carousel slide"data-ride="carousel"><!-- Indicators --><olclass="carousel-indicators hidden-xs"><lidata-target="#carousel-example-generic"data-slide-to="0"class="active"></li><lidata-target="#carousel-example-generic"data-slide-to="1"></li><lidata-target="#carousel-example-generic"data-slide-to="2"></li></ol><!-- Wrapper for slides --><divclass="carousel-inner"role="listbox"><divclass="item active"><imgclass="img-responsive"src="http://placehold.it/600x200/c69/?text=%20"alt="Slide 1"></div><divclass="item"><imgclass="img-responsive"src="http://placehold.it/600x200/69c/?text=%20"alt="Slide 2"></div><divclass="item"><imgclass="img-responsive"src="http://placehold.it/600x200/9c6/?text=%20"alt="Slide 3"></div></div><!-- Controls --><aclass="left carousel-control"href="#carousel-example-generic"role="button"data-slide="prev"><spanclass="glyphicon glyphicon-chevron-left"aria-hidden="true"></span><spanclass="sr-only">Previous</span></a><aclass="right carousel-control"href="#carousel-example-generic"role="button"data-slide="next"><spanclass="glyphicon glyphicon-chevron-right"aria-hidden="true"></span><spanclass="sr-only">Next</span></a></div><divclass="alert alert-danger hidden-xs text-center">
  Width > 767px. Make the window narrower.
</div><divclass="alert visible-xs text-center">
  Width < 768px. Indicators are hidden.
</div><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"crossorigin="anonymous"></script>

2. Indicators can be turned off

Add this CSS:

@media (max-width: 767px) {
  .carousel-indicators,
  .carousel-indicatorsli {
    cursor: default;
    pointer-events: none;
  }
}

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

.carousel-inner > .item > img {
  width: 100%;
}

@media (max-width: 767px) {
  .carousel-indicators,
  .carousel-indicatorsli {
    cursor: default;
    pointer-events: none;
  }
}
<divid="carousel-example-generic"class="carousel slide"data-ride="carousel"><!-- Indicators --><olclass="carousel-indicators"><lidata-target="#carousel-example-generic"data-slide-to="0"class="active"></li><lidata-target="#carousel-example-generic"data-slide-to="1"></li><lidata-target="#carousel-example-generic"data-slide-to="2"></li></ol><!-- Wrapper for slides --><divclass="carousel-inner"role="listbox"><divclass="item active"><imgclass="img-responsive"src="http://placehold.it/600x200/c69/?text=%20"alt="Slide 1"></div><divclass="item"><imgclass="img-responsive"src="http://placehold.it/600x200/69c/?text=%20"alt="Slide 2"></div><divclass="item"><imgclass="img-responsive"src="http://placehold.it/600x200/9c6/?text=%20"alt="Slide 3"></div></div><!-- Controls --><aclass="left carousel-control"href="#carousel-example-generic"role="button"data-slide="prev"><spanclass="glyphicon glyphicon-chevron-left"aria-hidden="true"></span><spanclass="sr-only">Previous</span></a><aclass="right carousel-control"href="#carousel-example-generic"role="button"data-slide="next"><spanclass="glyphicon glyphicon-chevron-right"aria-hidden="true"></span><spanclass="sr-only">Next</span></a></div><divclass="alert alert-danger hidden-xs text-center">
  Width > 767px. Make the window narrower.
</div><divclass="alert visible-xs text-center">
  Width < 768px. Indicators are turned off.
</div><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"crossorigin="anonymous"></script>

3. Indicators can be placed below the carousel

Add this CSS:

@media (max-width: 767px) {
  .carousel {
    margin-bottom: 7%;
  }   
  .carousel-indicators {
    bottom: auto;
    top: 105%;
  }
  .carousel-indicatorsli {
    border-color: #666;
  }
  .carousel-indicators.active {
    background-color: #666;
  }
}

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

.carousel-inner > .item > img {
  width: 100%;
}

@media (max-width: 767px) {
  .carousel {
    margin-bottom: 7%;
  }   
  .carousel-indicators {
    bottom: auto;
    top: 105%;
  }
  .carousel-indicatorsli {
    border-color: #666;
  }
  .carousel-indicators.active {
    background-color: #666;
  }
}
<divid="carousel-example-generic"class="carousel slide"data-ride="carousel"><!-- Indicators --><olclass="carousel-indicators"><lidata-target="#carousel-example-generic"data-slide-to="0"class="active"></li><lidata-target="#carousel-example-generic"data-slide-to="1"></li><lidata-target="#carousel-example-generic"data-slide-to="2"></li></ol><!-- Wrapper for slides --><divclass="carousel-inner"role="listbox"><divclass="item active"><imgclass="img-responsive"src="http://placehold.it/600x200/c69/?text=%20"alt="Slide 1"></div><divclass="item"><imgclass="img-responsive"src="http://placehold.it/600x200/69c/?text=%20"alt="Slide 2"></div><divclass="item"><imgclass="img-responsive"src="http://placehold.it/600x200/9c6/?text=%20"alt="Slide 3"></div></div><!-- Controls --><aclass="left carousel-control"href="#carousel-example-generic"role="button"data-slide="prev"><spanclass="glyphicon glyphicon-chevron-left"aria-hidden="true"></span><spanclass="sr-only">Previous</span></a><aclass="right carousel-control"href="#carousel-example-generic"role="button"data-slide="next"><spanclass="glyphicon glyphicon-chevron-right"aria-hidden="true"></span><spanclass="sr-only">Next</span></a></div><divclass="alert alert-danger hidden-xs text-center">
  Width > 767px. Make the window narrower.
</div><divclass="alert visible-xs text-center">
  Width < 768px. Indicators are placed below the carousel.
</div><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"crossorigin="anonymous"></script>

Solution 2:

Mobile devices register touch events.

So, in your click handler, you can distinguish between mouse and touch events.

If it is a touch event, don't do anything.

Post a Comment for "Bootstrap Carousel: Disable Indicators"