question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS Question: Fade transition for Carousel

See original GitHub issue

Issue description

  • components: Carousel
  • reactstrap version #5.0.0
  • import method es6 (I started with a blank React ES6 app on stackblitz.com)
  • react version #16.1.1
  • bootstrap version #4.0.0

What should be happening?

I’m trying to create a carousel in reactstrap that has a fade transition rather than the slide transition.

What is happening?

The carousel is rendered invisible. It is still there, occupying space in the layout and cycling through the slides, but nothing is visible.

Steps to reproduce issue

I started with a blank React ES6 app, added only the the carousel example in your docs, and then added custom CSS following this example:

.carousel-fade .carousel-item {
  display: block;
  position: absolute;
  opacity: 0;
  transition: opacity .75s ease-in-out;
}
.carousel-fade .carousel-item.active {
  opacity: 1;
}

html,
body,
.carousel,
.carousel-inner,
.carousel-item {
  width: 100%;
  height: 100%;
}

.carousel {
  position: absolute;
  top: 0;
  left: 0;
}

.carousel-item:nth-child(1) {
  background-color: red;
}
.carousel-item:nth-child(2) {
  background-color: blue;
}
.carousel-item:nth-child(3) {
  background-color: yellow;
}
  1. Start with blank React ES6 app on https://stackblitz.com
  2. Add dependencies: jquery, popper.js, bootstrap, reactstrap, react-popper, and react-transition-group.
  3. In index.js, import bootstrap/dist/css/bootstrap.min.css
  4. In index.js, replace App class with code from the Carousel example.
  5. Change render() call at the end to render(<Example />, document.getElementById('root'));.
  6. Add custom CSS to style.css as mentioned above.
  7. Add the following properties to the <Carousel/>:
    • keyboard={false}
    • pause={false}
    • ride="carousel"
    • interval="2000"
    • slide={false}
    • className="carousel-fade"

Error message in console

There are no errors logged to the console.

Code

https://stackblitz.com/edit/carousel-fade?file=index.js


Is there a way to create a carousel with a fade transition in reactstrap?

Side note: I don’t understand why Bootstrap has the .carousel-fade class if it requires custom CSS to actually make it fade…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
AustrisCcommented, Apr 11, 2018

Here is the SCSS I came up with for a smooth transition without the white flicker at the beginning.

.carousel-inner {
  .carousel-item {
    opacity: 0;
    top: 0;
    left: 0;
    width: 100%;
    display: block;
    position: absolute;
    transition: opacity 1s ease-in-out;

    &:first-of-type {
      position: relative;
    }
  }

  .active {
    opacity: 1;
  }
}
11reactions
jimmy121192commented, Aug 30, 2019

Just in case someone is still looking for a solution to this issue. Here is my way: just add className=“carousel-fade” in Carousel

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Bootstrap Carousel fade transition - Stack Overflow
Bootstrap 5 includes a "fade" effect that can be used by simply adding the carousel-fade class to the Carousel. By default, the transition...
Read more >
Bootstrap Carousel Fade Transition: How To + Template
Changing the transition effect of a Bootstrap carousel to fade instead of slide, is easy: it can be done just by adding an...
Read more >
5 Bootstrap Fade Carousel Slider - csshint - A designer hub
1. Bootstrap 4 Carousel Fade ; 2. Bootstrap Carousel Fade Transition ; 3. Fade to Zoom Carousel ; 4. Fade Carousel Slider ;...
Read more >
carousel-fade - Bootstrap CSS class
Bootstrap CSS class carousel-fade with source code and live preview. ... transition-duration: .6s; transition-property: opacity; } .carousel-item.active, ...
Read more >
Bootstrap 4 Fading Carousel Slider - YouTube
Get Our Full Bootstrap Website Building Course – Learn to build sites fast: https://goo.gl/6tzUxH Free Tech Courses - Web Design, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found