hola, por ahora me funciona con el incoveniente que de la flecha prev avanza y no retrocede, tengo bien asociado todo, lo que yo creo que esta mal es el size que no me debe tomar la propiedad length
export default class Slider{
constructor({elements,speed,animationFunc}){
this.elements = elements;
this.speed = speed;
this.animationFunc = animationFunc;
this.index=0;
this.size=elements.length;
this.innerNext = this.innerNext.bind(this);
this.innerPrev = this.innerNext.bind(this);
this.next = this.next.bind(this);
this.prev = this.prev.bind(this);
this.stop = this.stop.bind(this);
}
innerNext(){
this.index++;
if(this.index>=this.size) this.index = 0;
this.animationFunc(this.elements[this.index]);
}
innerPrev(){
this.index--;
if(this.index < 0) this.index = this.size - 1;
this.animationFunc(this.elements[this.index]);
}
next(){
this.innerNext();
if(this.interval){
this.stop();
this.play();
};
};
prev(){
this.innerPrev();
if(this.interval){
this.stop();
this.play();
};
};
play(){
this.interval = setInterval(this.innerNext,this.speed);
};
stop(){
clearInterval(this.interval);
};
}
********
let leftArrow = document.querySelector('.left-arrow');
let rightArrow = document.querySelector('.right-arrow');
leftArrow.addEventListener('click',slider.prev);
rightArrow.addEventListener('click',slider.next);
export default class Slider{
constructor({elements,speed,animationFunc}){
this.elements = elements;
this.speed = speed;
this.animationFunc = animationFunc;
this.index=0;
this.size=elements.length;
this.innerNext = this.innerNext.bind(this);
this.innerPrev = this.innerNext.bind(this);
this.next = this.next.bind(this);
this.prev = this.prev.bind(this);
this.stop = this.stop.bind(this);
}
innerNext(){
this.index++;
if(this.index>=this.size) this.index = 0;
this.animationFunc(this.elements[this.index]);
}
innerPrev(){
this.index--;
if(this.index < 0) this.index = this.size - 1;
this.animationFunc(this.elements[this.index]);
}
next(){
this.innerNext();
if(this.interval){
this.stop();
this.play();
};
};
prev(){
this.innerPrev();
if(this.interval){
this.stop();
this.play();
};
};
play(){
this.interval = setInterval(this.innerNext,this.speed);
};
stop(){
clearInterval(this.interval);
};
}
********
let leftArrow = document.querySelector('.left-arrow');
let rightArrow = document.querySelector('.right-arrow');
leftArrow.addEventListener('click',slider.prev);
rightArrow.addEventListener('click',slider.next);