Giter VIP home page Giter VIP logo

karusel's Introduction

Karusel

Karusel is a simple carousel plugin for jQuery Mobile.

You can visit the demo page at http://antonmaju.github.com/karusel

How to Use

Add reference to karusel.js script, then you can call the karusel plugin directly.

$('#carousel').karusel(options);

Alternatively, you can use data-role attribute

<div id="carousel" data-role="karusel"></div>

Options

The available options are:

  • source
    This option provides karusel a way to pull and render the data.

  • loop
    Sets the karusel's loop behavior.
    The default is false.

  • itemClass
    Sets the css class for individual item generated by karusel.
    The default is "item".

  • itemsClass
    Sets the css class for items element generated by karusel.
    The default is "items".

  • wrapperClass
    Sets the css class for wrapper element generated by karusel.
    The default is "karusel-wrapper".

  • prevItemClass
    Sets the css class for wrapper element generated by karusel.
    The default is "prev-item".

  • nextItemClass
    Sets the css class for wrapper element generated by karusel.
    The default is "next-item".

  • parentPadding
    Sets the padding size for karusel. The default is 15 (pixels).
    You may change it based on your jQuery Mobile theme.

  • itemSourceClass
    Sets the source item for karusel. This option is evaluated if the source option is not supplied.
    The default is 'item-source'.

  • wrapperSourceClass
    Sets the wrapper source for karusel. This option is evaluated if the source option is not supplied. The default is 'wrapper-source'.

All options can be set via data attribute. So as an example, you can use data-loop attribute for loop option and data-item-class attribute for itemClass option.

Events

  • itemscreated
    This event is trigerred anytime karusel renders its items. To use it, you need to bind the event to karusel selector.

    $('#carousel').bind('itemscreated', function(evt){ }).karusel();

Data Source

Data source object can be any object as long as it has the following methods.

{
	getDataAt: function(widget, index){
		//retrieve items from data source
		//widget : the instance of karusel
		//index : the index of desired item 
	},
	count: function(widget){
		//get total number of items
		//widget: the instance of karusel
	},
	render: function (widget, data, $item) {
        //render html representation of the data
		//widget: the instance of karusel
		//data: the data to be rendered
		//$item : jquery object representing item element
    }
}

There are 2 built-in data source classes, ArraySource and DomSource to ease the data source creation.

ArraySource

You use ArraySource to supply the data source from array. It has 1 constructor parameter, which is the array instance.

var arr =[1,2,3];

var store = new $.Karusel.ArraySource(arr);
$('#carousel').karusel({
	source: store
});

You may want to override its render method if your array item is custom object.

var arr=[{id:1, name:'John'}, {id:2,name:'Mary'}];

var store = new $.Karusel.ArraySource(arr);
store.render = function (widget, data, $item) {
	var html = '<div class="title">'+data.name+'</div>';
	$item.html(html);
};

$('#carousel').karusel({
	source: store
});

DomSource

DomSource is the default data source. You define the data source from the existing DOM element. Given the following HTML element

<ol class="wrapper-source">
	<li class="item-source"><span>Item 1</span></li>
	<li class="item-source"><span>Item 2</span></li>
</ol>

You will need to supply itemSelector and wrapperSelector option to DomSource class.

var store = new $.Karusel.DomSource({
	itemSource: 'item-source',
	wrapperSource: 'wrapper-source'
});
$('#carousel').karusel({
	source: store
});

karusel's People

Contributors

antonmaju avatar

Stargazers

softcup avatar

Watchers

James Cloos avatar  avatar

karusel's Issues

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.