Ich habe gerade Animation durch requestAnimationFrame gelernt, und ich dachte über diese Frage nach. Ich habe eine einfache Animation Methode:
animate: function(callbackObj, duration) {
var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame;
var startTime = 0, percentage = 0, animationTime = 0;
duration = duration*1000 || 1000;
var animate = function(timestamp) {
if (startTime === 0) {
startTime = timestamp;
} else {
animationTime = timestamp - startTime;
}
if (typeof callbackObj.start === 'function' && startTime === timestamp) {
callbackObj.start();
requestAnimationFrame(animate);
} else if (animationTime < duration) {
if (typeof callbackObj.progress === 'function') {
percentage = animationTime/duration;
callbackObj.progress(percentage);
}
requestAnimationFrame(animate);
} else if (typeof callbackObj.done === 'function'){
callbackObj.done();
}
};
return requestAnimationFrame(animate);
},
Es ist im Grunde eine rekursive Methode, die jedesmal, wenn der Bildschirm aktualisiert aktualisiert. Die Methode übernimmt ein Callback-Objekt mit Funktionen unter den Eigenschaften .start, .progress und .done.
ich Ihren Code ein wenig geändert:
_autoScroll: function() {
var sequenceObj = {};
var seconds = 2;
var rangeInPixels = 500;
sequenceObj.progress = (function(percentage) {
this.$.itemList.scroll(0, this.easeInOutQuad(percentage)*rangeInPixels);
}).bind(this);
this.animate(sequenceObj, seconds);
},
ich die easeInOut von Robert Penners Beschleunigungsfunktionen bekam:
easeInOutQuad: function (t) { return t<.5 ? 2*t*t : -1+(4-2*t)*t },
und Viola:
http://jsfiddle.net/5uLhu6qa/
Es ist nicht genau wonach Sie fragen, aber es ist ein Anfang, den Sie fortführen können inue mit.