Giter Club home page Giter Club logo

carousel-js's Introduction

Carousel widget

This is a generic carousel widget which can be used with any content. Highly customizable and extendable. It works in any browser on any device.

Your pull requests are more than welcome and we're happy for any contribution.

travis status

Add an image gallery to your app

Below is a sample of how you create a simple image carousel. Add the script to the bottom of the page

<script src="carousel-1.0.0.min.js"></script>

Then add markup for listing the images.

<div>
    <div id="imageList">
        <img src="" alt="">
        <img src="" alt="">
    </div>
    <div id="prevNextNavigation" class="nextprev">
        <a class="prev" title="Previous"><span class="hidden">Previous</span></a>
        <a class="next" title="Next"><span class="hidden">Next</span></a>
    </div>
</div>

Now let's wire up the JS code required to make this thing work. This should be in a separate file loaded after the carousel lib.

(function(carousel){
    var sourceImageList = document.getElementById("imageList");
    var imageList = carousel.elementList.create(sourceImageList);
    var controller = carousel.controller.create(imageList);

    var imageProjector = carousel.animatedProjector.create(controller, imageList, {
        duration: 500,
        animator: carousel.horizontalSlider
    });
    var imageCarousel = imageProjector.buildCarousel();
    carousel.setupClickNavigation(
        controller,
        imageList,
        document.getElementById("prevNextNavigation")
    );
    carousel.setupKeyboardNavigation(controller);
    carousel.setupTouchNavigation(controller, imageCarousel);
    sourceImageList.style.display = "none";

    controller.start();
}(FINN.carousel));

That's it! You can use this same setup for things other than images, you can loop through any type of DOM node. Wether it's an image, canvas, svg or whatever.

The carousel consists of many components which can easily be composed together to give the carousel different behaviours. Below are some samples, the rest is in the source code.

More sample usages

There are a few samples in the samples folder which shows how you can combine the different components to fit your requirements.

Samples in the wild

Feel free to add your samples to this section or let us know if you use it.

Building the source

###Preparing the workspace You will need Node/NPM and Grunt installed. Install required development dependencies:

$ cd carousel-js && npm install
$ npm install -g grunt grunt-cli
$ grunt

This runs tests and puts a new package in your local dist folder, ready to use.

Running tests

Currently all tests are run using Karma runner. Tests use the Buster assertion library and Jasmine for writing tests. Jasmine was selected due to the fact it helped us move away from JsTestDriver.

    $ npm test

    $ grunt karma

    $ ./node_module/.bin/karma start

Component

The carousel package contains numerous components which can be packaged together to give you exactly the kind of carousel widget you want.

Dependencies

Some components rely on jQuery, we are working to lose those as soon as possible.

FAQ

What about AMD support?

The pieces which make up the carousel widget are not AMD modules. However if you have a look in the samples directory you can se how to use the widget in an AMD environment

Other module formats can take similar approaches. There are currently no plans to expose the individual modules in the carousel to different module formats.

I get an error with the bind function

The carousel requires an ES5 shim to be present for browsers which doesn't have the bind function available.

Original authors

carousel-js's People

Contributors

cjohansen avatar eirslett avatar jstnhlj avatar leftiefriele avatar magnars avatar maurizi avatar msolli avatar stigkj avatar sveisvei avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.