salve, ho realizzato una classe in javascript per lo slide di un div
cosa mi consigliate per rendere il movimento fluido e magari renderlo più lento di com'è ora? se modifico il tempo del setTimeout l'animazione sembra scattosa...inoltre il controllo per l'arrivo è corretto così oppure lo fareste in un altro modo?Codice PHP:
function Slider(cosa){
this.tempo = 5;
this.vel = 10;
this.mov = 2;
this.id = cosa;
this.start = 100-document.getElementById(this.id).offsetHeight;
if(this.start%2!=0) this.start++;
this.end = this.start+document.getElementById(this.id).offsetHeight;
if(this.end%2!=0) this.end++;
document.getElementById(this.id).style.top=this.start+"px";
this.getPosition = function(){
return parseInt(document.getElementById(this.id).style.top);
};
this.scendilo = function(){
var scope = this;
if(this.getPosition() < this.end){
document.getElementById(this.id).style.top=this.getPosition()+this.mov+"px";
setTimeout(function(){scope.scendilo()}, this.vel);
}
};
this.salilo = function(){
var scope = this;
if(this.getPosition() > this.start){
document.getElementById(this.id).style.top=this.getPosition()-this.mov+"px";
setTimeout(function(){scope.salilo()}, this.vel);
}
};
this.move = function(){
if (this.getPosition() == this.start) {
this.scendilo();
}
else{
this.salilo();
}
}
}