javascript - Animating a custom carousel with React.js -


I made a carousel with React.js, until I came into the animation problem it was simple. The carousel is classic, it is composed of "slides" of the current slide and small bullet content of small thumbnails to navigate between the slides.

The carousel component is data-driven, which means that it has passed its content as a JavaScript array of objects, each slide has a li tag to be ul < / Code>, and just move margin-left to ul from one slide to another.

I am thinking that I should use ReactTransitionGroup or ReactCSSTransitionGroup to animate the transition from one code to another. The transition is basically a sliding effect that goes from left to right when moving from one slide to another.

I understand that ReactTransitionGroup s API is useful during adding or deleting some content. Here I will not want to add / remove any slides, with the animation I will change the visible.

My difficulty is to wrap my head around this, that I developed a static (aka akiman aka) carousel where the slide component currently displayed is the only state saved in the slide. The array has an index of slides. So when I click on a thumbnail to navigate to the slide number n , the only thing I am updating this internal state is, then rendering to left style It takes care of setting the property based on this index.

I do not think how can I add an animation to this carousel. Any help / hints greatly appreciated.

The answer was quite simple, no need to use ReactTransitionGroup Or feedback CSSTransitionGroup . I just used inline CSS with CSS 3 transition

In the Render function, we dynamically calculate the left property because since our slides have all the same width, the slides are displayed inline and on the parent element Only one slide appears for overflow: hidden , our dynamic class code looks like this:

  var styles = {status: "full", top: 0, left: IMG_WIDTH * (this.props.idx - this.props.activeIdx), Zindex: 100, Infection: 'left 1s', f Dhai: '100%'};  

Do not see the formula too much, it's an implementation description.

Next, note that our carousel is "infinite," which means that the transition is always the same path - left to right - even when on the first or last element The issue of playing with the index of the array of materials was "just". Side note (even troll): The hard part was even better because it had pure algorithms with data, because it was better to manipulate the difficult and diplomatic direct dom. No more for this stuff, and even for the rest of our website.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -