Web サイトにある多くのアニメーションを管理するオブジェクト コンストラクターがあります。パラメーターを start 関数に渡したいと思います。このパラメーターはコールバックです。oncomplete のように、達成したいのはアニメーション停止いくつかの要素を表示したい。問題は、コールバックを渡すことですが、何も起こらず、関数がパラメーターを取得しない理由が本当にわかりません。誰かが私を助けてくれることを願って、いくつかのコードを残します。
// CONSTRUCTOR WHO MANAGE THE ANIMATIONS FOR THE WEBSITE
function SpriteAnimation(frameWidth, spriteWidth, spriteElement, shouldLoop, frameRate){
this.frameWidth = frameWidth;
this.spriteWidth = spriteWidth;
this.selector = document.getElementById(spriteElement);
this.shouldLoop = shouldLoop ;
this.curPx = 0;
this.frameRate = frameRate;
}
SpriteAnimation.prototype.start = function(callback){
this.selector.style.backgroundPosition = "-" + this.curPx + "px 0px";
this.curPx += this.frameWidth;
if (this.curPx < (this.spriteWidth - this.frameWidth)){
setTimeout(this.start.bind(this), this.frameRate);
} else if (this.shouldLoop) {
this.curPx = 0;
this.start();
if(callback && typeof callback === "function"){
callback();
}
}
};
今、コールバックを呼び出すために使用しているコードの一部:
var letter = new SpriteAnimation(789.695652, 18163, "letter", false, 53.3);
letter.start(function(){
$("#form-field").fadeIn();
});
おそらくコンテキストを渡していないのか、そのようなものなのかはわかりませんが、実際にはJavaScriptを学んでいるので、オブジェクトでどのように機能するのかよくわかりません。以前は、アニメーションごとにたくさんの変数と関数がありました。