Shyam has posted 8 posts at DZone. You can read more from them at their website. View Full User Profile

A Reusable AngularJS Carousel Directive

07.12.2013
| 6328 views |
  • submit to reddit
Location: 
India

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:

SEE THE DEMO

GET IT ON GITHUB

Fundoo Solutions Website

0
Published at DZone with permission of its author, Shyam Seshadri.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)