简体   繁体   English

引导轮播放大到淡出

[英]Bootstrap Carousel ZoomIn to FadeOut

Hey so i'm customizing the Bootstrap Carousel to have a custom transition effect but am having a hard time achieving it. 嗨,所以我正在自定义Bootstrap Carousel,以具有自定义过渡效果,但很难实现它。 I believe this is do to my lack of understanding on how the carousel works exactly. 我认为,这是由于我对轮播的确切工作缺乏了解。 Anyways the effect that I am trying to achieve is a simple fade out which I found many examples of except the difference is the image will zoom in before it fades out into the next image. 无论如何,我试图实现的效果都是一个简单的淡入淡出 ,我发现了很多例子,除了区别在于图像会 淡入下一个图像之前放大。

In other words the image will have a transition: scale(1) to transition: scale(1.1) then it will opacity: 0 to opacity: 1 into the next image. 换句话说,图像将具有一个transition: scale(1)transition: scale(1.1)然后它将opacity: 0变为opacity: 1进入下一个图像。

I got 3 random images on google just to play around with and it seems that there are 2 problems here. 我在Google上获得了3张随机图像,只是想玩一下,看来这里有2个问题。

  1. the transition is not smooth 过渡不顺利
  2. the image will scale back down before it fades out into the next image. 图像会逐渐缩小,然后淡出为下一张图像。

Codepen: http://codepen.io/anon/pen/OWezyZ Codepen: http ://codepen.io/anon/pen/OWezyZ

My CSS: 我的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; }

This has been quite the challenge because again I lack the "understanding" on how the bootstrap carousel is actually working. 这一直是一个很大的挑战,因为我再次对引导旋转木马的实际工作方式缺乏“了解”。

Help is greatly appreciated, thank you! 非常感谢您的帮助,谢谢!

Here Codepen 这里Codepen

Note: notice additional line in JavaScript and remove active class from html 注意:注意JavaScript中的其他行并从html中删除active

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

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