Can the Twitter Bootstrap Carousel plugin fade in and out on slide transition

前端 未结 6 1184
时光取名叫无心
时光取名叫无心 2020-11-30 19:36

I have a very basic implementation of the Twitter Bootstrap Carousel plugin on a site that I am working on (http://furnitureroadshow.com/). I was just wondering if anyone h

6条回答
  •  悲哀的现实
    2020-11-30 20:06

    Came across this issue when using Bootstrap 3. My solution was to add the carousel-fade class to the carousel main DIV and slot the following CSS in, somewhere after the Bootstrap CSS is included:

    .carousel-fade .item {
      opacity: 0;
      -webkit-transition: opacity 2s ease-in-out;
      -moz-transition: opacity 2s ease-in-out;
      -ms-transition: opacity 2s ease-in-out;
      -o-transition: opacity 2s ease-in-out;
      transition: opacity 2s ease-in-out;
      left: 0 !important;
    }
    
    .carousel-fade .active {
      opacity: 1 !important;
    }
    
    .carousel-fade .left {
      opacity: 0 !important;
      -webkit-transition: opacity 0.5s ease-in-out !important;
      -moz-transition: opacity 0.5s ease-in-out !important;
      -ms-transition: opacity 0.5s ease-in-out !important;
      -o-transition: opacity 0.5s ease-in-out !important;
      transition: opacity 0.5s ease-in-out !important;
    }
    
    .carousel-fade .carousel-control {
      opacity: 1 !important;
    }
    

    The style transitions that Bootstrap applies mean that you have to have the mid-stride transitions (active left, next left) quickly, otherwise the item just ends up disappearing (hence the 1/2 second transition time).

    I haven't experimented with adjusting the .item and .left transition times, but they will probably need adjusting proportionally to keep the effect looking nice.

提交回复
热议问题