5 ms·
The tricky part in building carousel was always CSS part, not JavaScript part. If we removed HTML code from your JSX, you would have ~15 lines of JavaScript. I
by hex13 11y ago
The tricky part in building carousel was always CSS part, not JavaScript part.
If we removed HTML code from your JSX, you would have ~15 lines of JavaScript. It's simple, right? But it was always simple. I've built carousels in jQuery and JS part was also like 15-18 lines of code maybe.
CSS was trickier and I admit that CSS tweaking can actually take "day or two" (have you tried building simple carousel in pure JavaScript + <canvas>? It is be super easy when we exclude CSS problem from it).
Because CSS is a big freestyle there are many possible implementations of carousel in CSS. You used translate3D. Maybe this made all the difference. I think that you don't need React to calculate variable `offset` and assign it to CSS property `translate3D`. You could do this in jQuery as well.
Although React components are more modular and reusable off course. And if you have project written in React it's natural that everything is declared as React component. I just don't buy "React made possible to do it in simple way" part.