Over a million developers have joined DZone.

A Reusable AngularJS Carousel Directive

DZone's Guide to

A Reusable AngularJS Carousel Directive

· ·
Free Resource

Every cool app needs a Carousel. Its not cool till it has one. And so, there are a dozen or so variations of an AngularJS Carousel Directive out there in the wild. But here at Fundoo Solutions, we felt we needed yet another one. So why on earth would we create yet another one?

Well, we did the sane things first. We

  1. Modified Twitter Bootstrap to use its Carousel as a directive
  2. Modified tons of jQuery carousels
  3. Finally tried writing our own

When we started, our aim was to just show some data in a carousel. Simple, and Twitter Bootstrap worked great for it. But then, we had a requirement where there would be potentially 3000 – 4000 elements to be shown in the carousel. And then someone added a requirement that it had to work in IE9. And then in IE8. And thus, the AngularJS Carousel Directive was born.

We wanted to do a few things when we started out:

  1. Not load future elements unless it was to be displayed
  2. Try and reuse divs. So displaying 1000 elements should require the same number of Div elements as 10. This was especially needed to keep IE8 and IE9 fast.
  3. Work in IE8 and IE9. That meant, either No CSS3 transitions or have fallbacks. We ended up going completely with jQuery in the end.
  4. Allow changing the contents, jumping to a certain page without reloading the entire thing.
  5. Give enough flexibility to change the look, feel of the contents as well as the next / previous / jump to page buttons

We had the AngularJS expertise to pull this off, but we were still slightly worried about reusing the divs. But then, we happened upon Cubiq’s SwipeView. This was what we wanted (in terms of the endless loopable, responsive carousel). And so, this became the base for our AngularJS Carousel Directive.

We excavated, rewrote and modified significant portions of the code, till finally, we ended up with something that did everything we wanted and needed. So without further adieu:



Fundoo Solutions Website


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}