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.
thanks
IF YOU'RE USING BOOTSTRAP 3:
The event is 'slid.bs.carousel' not 'slid'
Augmenting @TheLittlePig, it needs to be slightly different if you're using Bootstrap 3 because the event to attach the callback to is different:
slid.bs.carousel
. Also, if you have multiple carousels on one page you'll need to pass a unique css id for the carousel into the event handler. Here is a modified version that I use on my Rails site:That is repeated for each carousel. The
<%=id%>
is a ruby expression that is replaced by a unique id for the given carousel. Tweak that bit for your needs according to the language of your choice.The difference is that the carousel's id is passed into the event handler function as event data so that the event handler can operate on the correct carousel. I also changed the
ready
event so that it triggers theslid.bs.carousel
event (instead of calling the function directly) so it passes the correct event data to the event handler for each carousel.The event handler is a function called
bs_carousel_slid
that I define elsewhere (those on Rails - it's in a file inapp/assets/javascripts
). The function is shown below: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
Bootply link