简体   繁体   English

引导轮播字幕动画

[英]Bootstrap Carousel Caption Animation

I'm trying to slideToggle the caption within my carousel on each slide change (including on init). 我正在尝试对每次幻灯片更改(包括init更改)在轮播中切换标题。 Actually it works well except when hovering. 实际上,除了将鼠标悬停时,它都可以正常工作。 I'd like to clear my timeout but it doesn't affect.. 我想清除超时,但不影响。

http://jsfiddle.net/M63jw/ http://jsfiddle.net/M63jw/

<script type='text/javascript'>
$(document).ready(function () {

    var carouselContainer = $('.carousel');
    var slideInterval = 3000;
    var carouselTimeout;

    carouselContainer
      .on('slid', function(){
        var caption = $(this).find('.active').find('.carousel-caption');

        caption.slideToggle();

        var carouselTimeout = setTimeout(function(){
          carouselTimeout = false;
          caption.slideToggle();
        }, slideInterval);

      })
      .on('slide', function(){
        if(carouselTimeout){
          clearTimeout(carouselTimeout);
          carouselTimeout = false;
        }
      });

    carouselContainer.carousel({
        interval: slideInterval,
        cycle: true,
        pause: "hover"
      }).trigger('slid');

    carouselContainer.hover(function(){
      clearTimeout(carouselTimeout);
      carouselTimeout = false;
    });

});
</script>

Any suggestions? 有什么建议么?

I believe you over-complicated things a little bit with the timeout, you can simply use the events of slid ans slide to toggle your caption like this: 我相信你过分复杂的事情超时一点点,你可以简单地使用事件的slidslide来切换您的标题是这样的:

var carouselContainer = $('.carousel');
var slideInterval = 3000;

function toggleCaption(){
    var caption = carouselContainer.find('.active').find('.carousel-caption');
    caption.slideToggle();
}

carouselContainer.carousel({
    interval: slideInterval,
    cycle: true,
    pause: "hover"
}).on('slid slide', toggleCaption).trigger('slid');

Demo fiddle 演示小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM