最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap carousel-caption animation - Stack Overflow

programmeradmin0浏览0评论

I need to customize the carousel of Boostrap3.

Basically what I'm trying to do is:

  • Making the caption appear a while after the image was loaded (to give the user the experience to see the pic a few secs, then the caption es in)
  • The caption should e from right to left.
  • The caption needs to fill the entire pic.

What have I tried?

The carrousel-caption shows up from bottom to top and it works only on the first slide.

Css markup

.carousel-caption {
    display: none;
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    padding-bottom: 30px;
    background: rgba(100, 100, 100, 0.5);
}

Followin a similar question, I'm using this .js

Js markup

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');

Here's a live demo

I need to customize the carousel of Boostrap3.

Basically what I'm trying to do is:

  • Making the caption appear a while after the image was loaded (to give the user the experience to see the pic a few secs, then the caption es in)
  • The caption should e from right to left.
  • The caption needs to fill the entire pic.

What have I tried?

The carrousel-caption shows up from bottom to top and it works only on the first slide.

Css markup

.carousel-caption {
    display: none;
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    padding-bottom: 30px;
    background: rgba(100, 100, 100, 0.5);
}

Followin a similar question, I'm using this .js

Js markup

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');

Here's a live demo

Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Jan 18, 2014 at 15:43 LuisLuis 5,9148 gold badges45 silver badges63 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

To slide right to left you can add jQuery UI and use it in toggle for additional features, to wait a bit before start the animation you can use delay.

The correct event to hook in bootstrap3 is slid.bs.carousel, see http://getbootstrap./javascript/#carousel

Code:

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

function toggleCaption() {
    $('.carousel-caption').hide();
    var caption = carouselContainer.find('.active').find('.carousel-caption');
    caption.delay(500).toggle("slide", {direction:'right'});
}

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

Demo: http://jsfiddle/IrvinDominin/Y6WH7/

UPDATE

To fix the caption height add this height: 100% !important; to its css rule.

Demo: http://jsfiddle/IrvinDominin/Y6WH7/1/

Here is a simple snippet to fade the active caption, other animations such as sliding can be achieved using css transitions or other methods or js animation libs.

$('.carousel').carousel({
  interval: 800000,
  pause: 'true',
  cycle: true
}).on('slide.bs.carousel', (e) => {
  $(e.relatedTarget).find('.carousel-caption').fadeOut(500)
}).on('slid.bs.carousel', (e) => {
  $(e.relatedTarget).find('.carousel-caption').fadeIn(500)
})
发布评论

评论列表(0)

  1. 暂无评论