GithubHelp home page GithubHelp logo

stigkj / carousel-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from finn-no/carousel-js

1.0 2.0 0.0 717 KB

Our general purpose carousel widget which can be used for multiple use-cases.

JavaScript 100.00%

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.

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";
}(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

Working with the carousel all you need to build it is to have Grunt installed and then just run the simple command:

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 JsTestDriver. Tests use the Buster assertion library. In order to run the tests you must have Grunt installed and make sure you have the Grunt JsTestDriver plugin installed. The configuration is aleady in the project grunt file.

To run the tests all you need to do is this:

java -jar node_modules/grunt-jstestdriver/lib/jstestdriver.jar --port 5555
grunt jstestdriver

Component

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

Dependencies

There are some dependencies, but we are looking to remove or replace the jQuery and Buster dependencies.

There are some components which rely on jQuery, but we are working to get rid of those as soon as possiblle

Contributors

carousel-js's People

Contributors

leftiefriele avatar

Stargazers

 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.