Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  132] [ 5]  / answers: 1 / hits: 22025  / 11 Years ago, mon, december 9, 2013, 12:00:00

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 the control successfully but on page load it is as if the carousel first item is in the middle and the user can either go all the way through via the left or right controls.



http://bootply.com/99354



thanks


More From » jquery

 Answers
89

Bootply link



$('#myCarousel').on('slid', '', checkitem);  // on caroussel move
$('#myCarousel').on('slid.bs.carousel', '', checkitem); // on carousel move

$(document).ready(function(){ // on document ready
checkitem();
});

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

[#73844] Friday, December 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
longd

Total Points: 616
Total Questions: 110
Total Answers: 101

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;