1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
//prépare le slide des éléments
cswSlider.prototype.go = function(way)
{
this.clearTimer('go');
var stop = 0;
this.goTo(this.elements, 'left', stop, 2, 0, this.current);
}
//fait glisser un array d'éléments d'un point à un autre
cswSlider.prototype.goTo = function(elements, direction, stop, incrementation, callback, index)
{
var that = this;
if(!index) index = 0;
this.clearTimer(elements[0]);
var posElement = parseInt(eval("this.el(elements[index]).style."+direction));
if(posElement < stop) var increElement = "this.el(elements[i]).style."+direction+" = parseInt(this.el(elements[i]).style."+direction+") + "+incrementation+" + 'px'";;
if(posElement > stop) var increElement = "this.el(elements[i]).style."+direction+" = parseInt(this.el(elements[i]).style."+direction+") - "+incrementation+" + 'px'";
for(i = 0; i < elements.length; i++)
{
eval(increElement);
}
if(posElement == stop){ this.clearTimer(elements[0]); if(callback){ eval(callback); }}
else{ this.timer[elements[0]] = setTimeout(function(){ that.goTo(elements, direction, stop, incrementation, callback, index); }, this.speed); }
}
//clean le timer des slide
cswSlider.prototype.clearTimer = function(index, all)
{
if(this.timer[index] && !all)
{
clearTimeout(this.timer[index]);
this.timer[index] = false;
}
if(all)
{
for(i in this.timer)
{
clearTimeout(this.timer[i]);
this.timer[i] = false;
}
}
}
//retourne un element du dom par son id
cswSlider.prototype.el = function(id)
{
return document.getElementById(id);
} |
Partager