问题
I am using bootstrap to make a carousel. The problem however is that I cant seem to figure out how I can call a function every time the carousel makes a cycle (with that I mean the automatic cycle function of the carousel). Anyone got any ideas for this?
Where I need it for is the following: Except for the carousel I have all pictures (from the carousel) as thumbs, so you have something like a photo album. Then I can click on any of those thumbs and I go directly to it. Then I make the thumb 'active' (which is basically a black border instead of a grey one) and then I make the previous thumb (the one that was active when I clicked on it) back to normal. But... when the carousel is cycling around (which looks pretty awesome) I want to keep the active thumb up to date. The only thing that I need in order to do that, is being able to call a function on the same moment that the carousel makes a cycle.
回答1:
As found in the documentation for the Twitter Bootstrap Carousel plugin, the carousel fires two events that you can listen for, slide
and slid
. Try listening to one of these events, and then executing the code you need in the callback.
Example
$('body').on('slid', function (e) {
//do stuff in here
});
来源:https://stackoverflow.com/questions/11485327/bootstrap-carousel