Over a million developers have joined DZone.

Data Slider //JavaScript Class

·


[UPDATED CODE AND HELP CAN BE FOUND HERE]



//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/classes/data-slider [v1.0]

( DataSlider = function( onchange, interval, args ){
	var i = DataSlider.instances = DataSlider.instances || [], o = this;
	( o.c = 0, o.timer = null, o.interval = ( o.onchange = ( o.data = [].slice.call( arguments, 0 ) ).shift(), o.data.shift() ), i[o.index = i.length] = o );
} ).prototype = {
	stop: function(){ clearTimeout( this.timer ); },
	play: function(){ this.timer = setInterval( "DataSlider.instances[" + this.index + "].next()", this.interval ); },
	show: function( x ){ this.c = x; this.onchange( this.data[ x ] ); },
	previous: function(){ this.show( this.c > 0 ? --this.c : this.data.length-1 ); },
	next: function(){ this.show( ( this.c + 1 ) % this.data.length ); }
};



Example


Rotacionador de objetos
:]
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}