Bootstrap Carousel放大到FadeOut

时间:2017-03-02 04:08:03

标签: javascript jquery html css twitter-bootstrap

嘿所以我定制Bootstrap Carousel以获得自定义过渡效果,但我很难实现它。我相信这是因为我对旋转木马的工作方式缺乏了解。无论如何,我想要实现的效果是一个简单的淡出,我发现很多例子,除了差异是图像放大之后淡出进入下一张图片。

换句话说,图片会有transition: scale(1)transition: scale(1.1),然后它会opacity: 0opacity: 1进入下一张图片。

我在google上有3个随机图像只是为了玩,似乎这里有2个问题。

  1. 过渡不顺利
  2. 图像将在淡入下一图像之前缩小。
  3. Codepen: http://codepen.io/anon/pen/OWezyZ

    我的CSS:

    .carousel-inner {
      position: relative;
      display: block;
      top: 0;
      left: 0;
    }
    
    
    /*
    inspired from http://codepen.io/Rowno/pen/Afykb 
    */
    
    .carousel-inner .item {
      opacity: 0;
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: auto;
      -webkit-transition: opacity 2s linear;
      -moz-transition: opacity 2s linear;
      -o-transition: opacity 2s linear;
      transition: opacity 2s linear;
    }
    
    .carousel-inner .item.active {
      opacity: 1;
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: auto;
    }
    
    .item img {
      display: block;
      position: relative;
      top: 0;
      left: 0;
      -webkit-transition: transform 10s linear;
      -moz-transition: transform 10s linear;
      -o-transition: transform 10s linear;
      transition: transform 10s linear;
      -webkit-transform: scale(1);
      transform: scale(1);
    }
    
    .active img {
      -webkit-transform: scale(1.1);
      transform: scale(1.1);
      position: relative;
      top: 0;
      left: 0;
    }
    
    
    /*
    WHAT IS NEW IN 3.3: "Added transforms to improve carousel performance in modern browsers."
    now override the 3.3 new styles for modern browsers & apply opacity
    */
    
    @media all and (transform-3d),
    (-webkit-transform-3d) {
      .carousel-inner > .item.next,
      .carousel-inner > .item.active.right {
        display: block;
        opacity: 0;
        transform: scale(1) translateZ(0);
        -webkit-transform: scale(1) translateZ(0);
      }
      .carousel-inner > .item.prev,
      .carousel-inner > .item.active.left {
        display: block;
        opacity: 0;
        -webkit-transform: scale(1.1) translateZ(0);
        transform: scale(1.1) translateZ(0);
      }
      .carousel-inner > .item.next.left,
      .carousel-inner > .item.prev.right,
      .carousel-inner > .item.active {
        display: block;
        opacity: 1;
        transform: scale(1.1) translateZ(0);
        -webkit-transform: scale(1.1) translateZ(0);
      }
    }
    
    /* just for demo purpose */
    
    html,
    body,
    .carousel,
    .carousel-inner,
    .carousel-inner .item {
      height: 100%;
    }
    
    img { width: 100% !important; }
    

    这一直是一个挑战,因为我再次缺乏理解"关于bootstrap carousel实际上是如何工作的。

    非常感谢帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

此处Codepen

注意:请注意JavaScript中的其他行并从html中删除active